CS 1102 Final

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Consider the following block of Java code. How many times will it output "Hello"?for (int i = 1; i > 10; i++){System.out.println("Hello");} Select one: a. 0 b. 9 c. 1 d. 10 e. Way too many!

a. 0

Consider the following Java program. Which one of the following does NOT describe "Clicker"? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener { int count; JButton button; Clicker() { super("Click Me"); button = new JButton(String.valueOf(count)); add(button); button.addActionListener(this); setSize(200,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { count++; button.setText(String.valueOf(count)); } public static void main(String[] args) { new Clicker(); } } a. A "Clicker" object can be assigned to an "ActionEvent" variable. b. A "Clicker" object can be assigned to a "JFrame" variable. c. A "Clicker" object can be assigned to an "ActionListener" variable. d. A "Clicker" object responds to button clicks. e. The "Clicker" class can be run as a program.

a. A "Clicker" object can be assigned to an "ActionEvent" variable.

In a for loop, how many times does the continuation condition run? Select one: a. At least once, at the beginning of each iteration. b. At least once, at the end of each iteration. c. Exactly once. d. Zero or more times, at the beginning of each iteration. e. Zero or more times, at the end of each iteration.

a. At least once, at the beginning of each iteration.

n a while loop, how many times does the continuation condition run? Select one: a. At least once, at the beginning of each iteration. b. At least once, at the end of each iteration. c. Exactly once. d. Zero or more times, at the beginning of each iteration. e. Zero or more times, at the end of each iteration.

a. At least once, at the beginning of each iteration.

Which of the following types is NOT a primitive type? Select one: a. String b. boolean c. double d. char e. short

a. String

Consider the following line of Java code. System.out.println("Hello, World!"); "System" is which of the following? Select one: a. a class b. a method (subroutine) c. an object d. a parameter e. a statement

a. a class

Consider the following line of Java code. System.out.println("Hello, World!"); Which one of the following does NOT describe '"Hello, World!"'? Select one: a. a declaration b. an expression c. a literal d. a parameter e. a statement

a. a declaration

Consider the following Java method, which term best describes "'("Hello, World!")"? public static void main(String[] args) { System.out.println("Hello, World!"); } Select one: a. actual parameter or argument b. formal parameter c. method call d. modifier e. return type

a. actual parameter or argument

Which of the following keywords is useful for getting out of an infinite loop? Select one: a. break b. continue c. do d. switch e. while

a. break

Which of the following can a class NOT be used for? Select one: a. a container for static methods (subroutines) b. a container for static variables c. a primitive type d. a type for method parameters e. a type for variables

c. a primitive type

Each of the individual tasks that a CPU is working on is called: Select one: a. a message b. an address c. a thread d. a program counter e. an object

c. a thread

What is the output of the following Java program? class Food { String flavor = "bland"; } class Pepper extends Food { String flavor = "spicy"; } public class Lunch { public static void main(String[] args) { Food lunch = new Pepper(); System.out.println(lunch.flavor);} } Select one: a. spicy b. no output c. bland d. the program does not compile e. bland spicy

c. bland

Consider the following Java program. Which object registers event listeners? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener { int count; JButton button; Clicker() { super("Click Me"); button = new JButton(String.valueOf(count)); add(button); button.addActionListener(this); setSize(200,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { count++; button.setText(String.valueOf(count)); } public static void main(String[] args) { new Clicker(); } } Select one: a. button b. count c. super d. this e. e

a. button or e. e

Consider the following Java declaration and assignment statement. float x = y; Which one of the following types is "y" NOT allowed to be? Select one: a. double b. float c. int d. long e. short

a. double

Which one of the following is used in Java programming to handle asynchronous events? Select one: a. event handlers b. pragmatics c. protocols d. reserved words e. short circuits

a. event handlers

Which one of the following is used in Java programming to handle asynchronous events? Select one: a. event handlers b. short circuits c. pragmatics d. protocols e. reserved words Feedback

a. event handlers

What is the output of the following Java program? public class Food { static int count; private String flavor = "sweet"; Food(String s) { flavor = s; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food("spicy"); Food chile = new Food("spicy"); System.out.println(pepper == chile); } } Select one: a. false b. sweet c. true d. spicy e. smoky

a. false

Consider the following Java program. Which one of the following is a package? import java.awt.event.*; import javax.swing.*; public class MouseWhisperer extends JFrame implements MouseListener { MouseWhisperer() { super("COME CLOSER"); setSize(300,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addMouseListener(this); setVisible(true); } public void mouseClicked(MouseEvent e) { setTitle("OUCH"); } public void mousePressed(MouseEvent e) { setTitle("LET GO"); } public void mouseReleased(MouseEvent e) { setTitle("WHEW"); } public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); } public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); } public static void main(String[] args) { new MouseWhisperer(); } Select one: a. java.awt.event b. JFrame c. MouseEvent d. MouseListener e. this Feedback

a. java.awt.event

Assume "test" is a boolean variable. Which of the following expressions is equivalent to "test == true"? Select one: a. test b. !test c. test = true d. test.equals(true)

a. test

What is the output of the following Java program? class Food { String flavor = "bland"; } class Pepper extends Food { String flavor = "spicy"; Pepper(String flavor) { this.flavor = flavor; } } public class Lunch { public static void main(String[] args) { Pepper pepper = new Pepper("sweet"); System.out.println(pepper.flavor);} } Select one: a. the program does not compile b. bland c. no output d. spicy e. sweet

a. the program does not compile

Assume that the variables "x" and "y" both have type "int". Which one of the following is NOT a boolean expression? Select one: a. x = y b. x >= y c. ((x > 0) && (y > 0)) d. (x > 0) ? (x > y) : (x < y)

a. x = y

What is the output of the following Java program? class Sum { static int sum = 0; static void add(int i) { i++;} public static void main(String[] args) { for (int i = 0; i < 10; i++) add(sum); System.out.println(sum);}} Select one: a. 100 b. 0 c. 10 d. 45 e. 9

b. 0

What is the output of the following Java program? public class Food { static int count; private String flavor = "sweet"; Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food(); new Food(); System.out.println(pepper.count);}} Select one: a. 1 b. 2 c. sweet d. spicy e. The program does not compile.

b. 2

Consider the following Java statements. int x = 3; x = x++; What is the value of x after these statements are executed? Select one: a. 0 b. 3 c. 4 d. 5 e. The question is moot. The statements have a syntax error.

b. 3

Consider the following Java statements: int x = 3; x = x++; What is the value x is holding? Select one: a. 0 b. 3 c. 4 d. 5 e. The question is moot. The statements have a syntax error.

b. 3

Which one of the following claims about Java is INCORRECT? Select one: a. Constructors can be overloaded with different parameter lists. b. A default constructor is always provided by the compiler. c. A constructor's name must match the name of the class. d. A constructor can only be called with "new". e. A constructor's name is its return type.

b. A default constructor is always provided by the compiler.

n a do-while loop, how many times does the continuation condition run (if the loop has no break, return, or System.exit calls)? Select one: a. At least once, at the beginning of each iteration. b. At least once, at the end of each iteration. c. Exactly once. d. Zero or more times, at the beginning of each iteration. e. Zero or more times, at the end of each iteration.

b. At least once, at the end of each iteration.

A class that implements a listener interface does which of the following? Select one: a. It generates events. b. It handles events. c. It maintains an object directory. d. It records audio. e. It runs an event loop.

b. It handles events.

Consider the following Java program, which one of the following best describes "pepper"? public class Food { static int count; private String flavor = "sweet"; Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food(); System.out.println(pepper.getFlavor()); } } Select one: a. a method b. a class variable c. a local object variable d. an instance variable e. a constructor

c. a local object variable

Consider the following Java program. What is the superclass of "MouseWhisperer"? import java.awt.event.*; import javax.swing.*; public class MouseWhisperer extends JFrame implements MouseListener { MouseWhisperer() { super("COME CLOSER"); setSize(300,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addMouseListener(this); setVisible(true); } public void mouseClicked(MouseEvent e) { setTitle("OUCH"); } public void mousePressed(MouseEvent e) { setTitle("LET GO"); } public void mouseReleased(MouseEvent e) { setTitle("WHEW"); } public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); } public void mouseExited(MouseEvent e) { setTitle("COME CLOSER");} public static void main(String[] args) { new MouseWhisperer(); }} Select one: a. java.awt.event b. JFrame c. MouseEvent d. MouseListener e. this

b. JFrame

Consider the following class definition. Which variables can be used in the missing "println" expression on line 12? 1 public class PrintStuff 2 { 3 public static void main() 4 { 6 { 7 int i = -1; 8 System.out.println(_____); 9 } 10 int j = 1; 11 for (j = 0; j < 10; j++) { 12 System.out.println(_____); 13 } 14 { 15 int k; 16 for (k = 0; k < 10; k++) { 17 System.out.println(_____); 18 } 19 } 20 System.out.println(_____); 21 } 22 } Select one: a. Only "i" b. Only "j" c. Only "k" d. "i" and "j" e. "j" and "k"

b. Only "j"

Consider the following class definition. Which variables can be used in the missing "println" expression on line 20? 1 public class PrintStuff 2 { 3 public static void main() 4 { 6 { 7 int i = -1; 8 System.out.println(_____); 9 } 10 int j = 1; 11 for (j = 0; j < 10; j++) { 12 System.out.println(_____); 13 } 14 { 15 int k; 16 for (k = 0; k < 10; k++) { 17 System.out.println(_____); 18 } 19 } 20 System.out.println(_____); 21 } 22 } Select one: a. Only "i" b. Only "j" c. Only "k" d. "i" and "j" e. "j" and "k"

b. Only "j"

What is the output of the following Java program? import java.util.*; class ArrayGames { public static void main(String[] args) { int[] a = {1,2,3,4,5}; for (int i = 1; i < a.length; i++) a[i] = a[i-1]; System.out.println(Arrays.toString(a)); } } Select one: a. [0, 1, 2, 3, 4] b. [1, 1, 1, 1, 1] c. [1, 2, 3, 4, 5] d. [1, 4, 9, 16, 25] e. No output. It throws an exception.

b. [1, 1, 1, 1, 1]

Consider the following line of Java code. System.out.println("Hello, World!"); "println" is which of the following? Select one: a. a class b. a method (subroutine) c. an object d. a parameter e. a statement

b. a method (subroutine)

Consider the following Java program, what starts on line 4? 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } Select one: a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition

b. a statement

Which one of the following is an event handler? Select one: a. an event generator b. an event listener c. an event loop d. an event method e. java.awt.event

b. an event listener

Consider the following Java program. Which statement registers an object to receive events? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener { int count; JButton button; Clicker() { super("Click Me"); button = new JButton(String.valueOf(count)); add(button); button.addActionListener(this); setSize(200,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { count++; button.setText(String.valueOf(count)); } public static void main(String[] args) { new Clicker(); } } Select one: a. add(button); b. button.addActionListener(this); c. button.setText(String.valueOf(count)); d. setVisible(true); e. super("Click Me");

b. button.addActionListener(this);

Which one of the following types are not allowed for the expression in a switch statement? Select one: a. enum b. float c. int d. long e. String

b. float

Consider the following Java method, which term best describes "String[] args"? public static void main(String[] args) { System.out.println("Hello, World!"); } Select one: a. actual parameter or argument b. formal parameter c. method call d. modifier e. return type

b. formal parameter

Consider the following Java method, which term best describes "'System.out.println("Hello, World!")"? public static void main(String[] args) { System.out.println("Hello, World!"); } Select one: a. return type b. method call c. actual parameter or argument d. formal parameter e. modifier

b. method call

A subclass method can _____ a superclass method with the same name and parameter types. Select one: a. abstract b. override c. inherit d. implement e. extend

b. override

Consider the following Java program. Which object receives events? import java.awt.event.*; import javax.swing.*; public class MouseWhisperer extends JFrame implements MouseListener { MouseWhisperer() { super("COME CLOSER"); setSize(300,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addMouseListener(this); setVisible(true); } public void mouseClicked(MouseEvent e) { setTitle("OUCH"); } public void mousePressed(MouseEvent e) { setTitle("LET GO"); } public void mouseReleased(MouseEvent e) { setTitle("WHEW"); } public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); } public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); } public static void main(String[] args) { new MouseWhisperer(); } } Select one: a. MouseEvent b. this c. MouseListener d. java.awt.event e. JFrame

b. this

Consider the following block of Java code. How many times will it output "Hello"? for (int i = 1; i < 10; i++) { System.out.println("Hello"); } Select one: a. 0 b. 1 c. 9 d. 10 e. Too many!

c. 9

What is the output of the following Java program? import java.util.*; class ArrayGames { public static void main(String[] args) { int[] a = {1,2,3,4,5}; for (int c : a) c *= c; System.out.println(Arrays.toString(a)); } } Select one: a. [0, 1, 2, 3, 4] b. [1, 1, 1, 1, 1] c. [1, 2, 3, 4, 5] d. [1, 4, 9, 16, 25] e. No output. It throws an exception.

c. [1, 2, 3, 4, 5]

Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener { int count; JButton button; Clicker() { super("Click Me"); button = new JButton(String.valueOf(count)); add(button); button.addActionListener(this); setSize(200,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { count++; button.setText(String.valueOf(count)); } public static void main(String[] args) { new Clicker(); } } Select one: a. add(button); b. button.addActionListener(this); c. button.setText(String.valueOf(count)); d. setVisible(true); e. super("Click Me");

c. button.setText(String.valueOf(count));

Which of the following keywords is useful for loops that should always execute at least once? Select one: a. break b. continue c. do d. switch e. while

c. do

Consider the following Java program, which one of the following best describes "main"? public class Food { static int count; private String flavor = "sweet"; Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food(); System.out.println(pepper.getFlavor()); } } Select one: a. a static method b. a setter method c. gets executed when the program runs d. a public method e. a class method

c. gets executed when the program runs

Consider the following Java program. Which line gives the "Clicker" class access to the "JButton" class definition? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener { int count; JButton button; Clicker() { super("Click Me"); button = new JButton(String.valueOf(count)); add(button); button.addActionListener(this); setSize(200,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { count++; button.setText(String.valueOf(count)); } public static void main(String[] args) { new Clicker(); } } Select one: a. button = new JButton(String.valueOf(count)); b. import java.awt.event.*; c. import javax.swing.*; d. JButton button; e. public class Clicker extends JFrame implements ActionListener {

c. import javax.swing.*;

public static void main(String[] args) { System.out.println("Hello, World!"); } Select one: a. return type b. method call c. modifier d. actual parameter or argument e. formal parameter

c. modifier

What is the output of the following Java program? abstract class Food { void printFlavor() {} } class Pepper extends Food {} public class Lunch { public static void main(String[] args) { Food lunch = new Pepper(); lunch.printFlavor(); } } Select one: a. spicy b. blandspicy c. no output d. bland e. the program does not compile

c. no output

Which of the following is NOT a valid identifier in Java? Select one: a. p b. Public c. public d. public23 e. PuBlIc_tWeNtY_3

c. public

What is the output of the following Java program? public class Food { static int count; private String flavor = "sweet"; Food(String s) { flavor = s; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food("spicy"); Food chile pepper; pepper.setFlavor("smoky"); System.out.println(chile.getFlavor()); } } Select one: a. true b. sweet c. smoky d. false e. spicy

c. smoky

What is the output of the following Java program? class Food { Food() { System.out.println("bland"); } Food(String flavor) { System.out.println(flavor); } } class Pepper extends Food { Pepper() { super("spicy"); } } public class Lunch { public static void main(String[] args) {Food lunch = new Pepper();} } Select one: a. blandspicy b. bland c. spicy d. no output e. the program does not compile

c. spicy

Assume "test" is a boolean variable. Which of the following expressions is equivalent to "test == false"? Select one: a. !test b. test.equals(true) c. test d. test = true

c. test

Which one of the following does NOT describe an ArrayList? Select one: a. It can be used in a for-each loop. b. It has a numbered sequence of elements. c. It provides efficient random access to its elements. d. Its elements can be a primitive type. e. The number of its elements can change.

d. Its elements can be a primitive type.

Consider the following Java program. What is the superclass of "Clicker"? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener { int count; JButton button; Clicker() { super("Click Me"); button = new JButton(String.valueOf(count)); add(button); button.addActionListener(this); setSize(200,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { count++; button.setText(String.valueOf(count)); } public static void main(String[] args) { new Clicker(); } } Select one: a. ActionEvent b. ActionListener c. JButton d. JFrame e. this

d. JFrame

Consider the following Java program. Which one of the following is an interface? import java.awt.event.*; import javax.swing.*; public class MouseWhisperer extends JFrame implements MouseListener { MouseWhisperer() { super("COME CLOSER"); setSize(300,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addMouseListener(this); setVisible(true); } public void mouseClicked(MouseEvent e) { setTitle("OUCH"); } public void mousePressed(MouseEvent e) { setTitle("LET GO"); } public void mouseReleased(MouseEvent e) { setTitle("WHEW"); } public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); } public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); } public static void main(String[] args) { new MouseWhisperer(); } } Select one: a. java.awt.event b. JFrame c. MouseEvent d. MouseListener e. this

d. MouseListener

Consider the following class definition. Which variables can be used in the missing "println" expression on line 12? 1 public class PrintStuff 2 { 3 public static void main() 4 { 6 { 7 int i = -1; 8 System.out.println(_____); 9 } 10 int j = 1; 11 for (j = 0; j < 10; j++) { 12 System.out.println(_____); 13 } 14 { 15 int k; 16 for (k = 0; k < 10; k++) { 17 System.out.println(_____); 18 } 19 } 20 System.out.println(_____); 21 } 22 } Select one: a. Only "i" b. "i" and "j" c. Only "k" d. Only "j" e. "j" and "k

d. Only "j"

Consider the following class definition. Which variables can be used in the missing "println" expression on line 20? 1 public class PrintStuff 2 { 3 public static void main() 4 { 6 { 7 int i = -1; 8 System.out.println(_____); 9 } 10 int j = 1; 11 for (j = 0; j < 10; j++) { 12 System.out.println(_____); 13 } 14 { 15 int k; 16 for (k = 0; k < 10; k++) { 17 System.out.println(_____); 18 } 19 } 20 System.out.println(_____); 21 } 22 } Select one: a. "i" and "j" b. "j" and "k" c. Only "i" d. Only "j" e. Only "k"

d. Only "j"

What does a Java compiler do? Select one: a. Runs Java programs b. Translates byte code in ".class" files into machine language c. Translates source code in ".class" files into machine language d. Translates source code in ".java" files into Java byte code in ".class" files e. Translates source code in ".java" files into machine language

d. Translates source code in ".java" files into Java byte code in ".class" files

What is the output of the following Java program? import java.util.*; class ArrayGames { public static void main(String[] args) { int[][] a = {{5,4,3,2,1},{-1,-2,-3,-4,-5}}; for (int[] b : a) Arrays.sort(b); for (int[] b : a) System.out.print(Arrays.toString(b)); } } Select one: a. [-5, -4, -3, -2, -1] b. [-5, -4, -3, -2, -1][1, 2, 3, 4, 5] c. [1, 2, 3, 4, 5] d. [1, 2, 3, 4, 5][-5, -4, -3, -2, -1] e. [5, 4, 3, 2, 1][-1, -2, -3, -4, -5]

d. [1, 2, 3, 4, 5][-5, -4, -3, -2, -1]

What is the output of the following Java program? import java.util.*; class ArrayGames { public static void main(String[] args) { int[] a = {1,2,3,4,5}; for (int i = 0; i < a.length; i++) a[i] *= a[i]; System.out.println(Arrays.toString(a)); } } Select one: a. [0, 1, 2, 3, 4] b. [1, 1, 1, 1, 1] c. [1, 2, 3, 4, 5] d. [1, 4, 9, 16, 25] e. No output. It throws an exception.

d. [1, 4, 9, 16, 25]

Consider the following line of Java code. System.out.println("Hello, World!"); "Hello ,World" is which of the following? Select one: a. a class b. a method (subroutine) c. an object d. a parameter e. a statement

d. a parameter

Consider the following Java program, which one of the following best describes "setFlavor"? public class Food { static int count; private String flavor = "sweet"; Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food(); System.out.println(pepper.getFlavor()); } } Select one: a. a class method b. a static method c. gets executed when the program runs d. a setter method e. a public method

d. a setter method

Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What starts on line 4? Select one: a. a class definition b. a variable declaration c. a comment d. a statement e. a method (subroutine) definition

d. a statement

Consider the following Java program. Which statement places a button in a window? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener { int count; JButton button; Clicker() { super("Click Me"); button = new JButton(String.valueOf(count)); add(button); button.addActionListener(this); setSize(200,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { count++; button.setText(String.valueOf(count)); } public static void main(String[] args) { new Clicker(); } } Select one: a. button.addActionListener(this); b. setVisible(true); c. super("Click Me"); d. add(button); e. button.setText(String.valueOf(count));

d. add(button);

Consider the following Java program, which one of the following best describes "flavor"? public class Food { static int count; private String flavor = "sweet"; Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food(); System.out.println(pepper.getFlavor()); } } Select one: a. a local object variable b. a method c. a constructor d. an instance variable e. a class variable

d. an instance variable

Which of the following should be used to compare the contents of two String objects in Java? a. = b. == c. cmp d. equals e. ?

d. equals

Consider the following Java method, which term best describes "public"? public static void main(String[] args) { System.out.println("Hello, World!"); } Select one: a. actual parameter or argument b. formal parameter c. method call d. modifier e. return type

d. modifier

Consider the following first line from a Java method definition. public static boolean compute(int n, float x) {Which one of the following lines could begin a method that legally overloads the above method? Select one: a. private static boolean compute(int n, float x) { b. public boolean compute(int n, float x) { c. public static int compute(int n, float x) { d. public static boolean compute(float n, int x) { e. public static boolean compute(int x, float n) {

d. public static boolean compute(float n, int x) {

Consider the following Java program. Which statement displays a window with a button on the screen? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener { int count; JButton button; Clicker() { super("Click Me"); button = new JButton(String.valueOf(count)); add(button); button.addActionListener(this); setSize(200,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { count++; button.setText(String.valueOf(count)); } public static void main(String[] args) { new Clicker(); } } Select one: a. add(button); b. button.addActionListener(this); c. button.setText(String.valueOf(count)); d. setVisible(true); e. super("Click Me");

d. setVisible(true);

Which of the following keywords is useful for processing lists of menu options? Select one: a. break b. continue c. do d. switch e. while

d. switch

Which of the following keywords is useful for making a loop that may execute forever or may not execute at all? Select one: a. continue b. switch c. break d. while e. do

d. while

What is output by the following Java program? class Compute { static int compute() { return 42; } static int compute(int i) { return i+1; } public static void main(String[] args) { System.out.println(compute(compute(0))); } } Select one: a. 42 b. 0 c. 1 d. 43 e. 2

e. 2

Consider the following Java program. Which line declares an instance object variable? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener { int count; JButton button; Clicker() { super("Click Me"); button = new JButton(String.valueOf(count)); add(button); button.addActionListener(this); setSize(200,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e) { count++; button.setText(String.valueOf(count)); } public static void main(String[] args) { new Clicker(); }} Select one: a. public static void main(String[] args) { new Clicker(); } b. public void actionPerformed(ActionEvent e) { c. int count; d. button = new JButton(String.valueOf(count)); e. JButton button;

e. JButton button;

In a for loop, how many times does the update run? Select one: a. Zero or more times, at the beginning of each iteration. b. At least once, at the beginning of each iteration. c. At least once, at the end of each iteration. d. Exactly once. e. Zero or more times, at the end of each iteration.

e. Zero or more times, at the end of each iteration.

Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? Select one: a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition

e. a class definition

Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 3? Select one: a. a statement b. a class definition c. a variable declaration d. a comment e. a method (subroutine) definition

e. a method (subroutine) definition

Consider the following line of Java code. System.out.println("Hello, World!"); The full line of code is which of the following? Select one: a. a class b. a method (subroutine) c. an object d. a parameter e. a statement

e. a statement

What is the output of the following Java program? class Food { String flavor = "bland"; void printFlavor() { System.out.println(flavor); } } class Pepper extends Food { String flavor = "spicy"; } public class Lunch { public static void main(String[] args) { Food lunch = new Pepper(); lunch.printFlavor();} } Select one: a. spicy b. no output c. the program does not compile d. bland spicy e. bland

e. bland

Which of the following keywords is useful for loops that should always execute at least once? Select one: a. continue b. break c. while d. switch e. do

e. do

Consider the following Java method, which term best describes "void"? public static void main(String[] args) { System.out.println("Hello, World!"); } Select one: a. actual parameter or argument b. formal parameter c. method call d. modifier e. return type

e. return type

What is the output of the following Java program? public class Food { static int count; private String flavor = "sweet"; Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food(); System.out.println(pepper.getFlavor()); } } Select one: a. 2 b. 1 c. spicy d. The program does not compile. e. sweet

e. sweet

Consider the following Java program. Which object registers event listeners? import java.awt.event.*; import javax.swing.*; public class MouseWhisperer extends JFrame implements MouseListener { MouseWhisperer() { super("COME CLOSER"); setSize(300,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addMouseListener(this); setVisible(true); } public void mouseClicked(MouseEvent e) { setTitle("OUCH"); } public void mousePressed(MouseEvent e) { setTitle("LET GO"); } public void mouseReleased(MouseEvent e) { setTitle("WHEW"); } public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); } public void mouseExited(MouseEvent e) { setTitle("COME CLOSER");} public static void main(String[] args) { new MouseWhisperer(); }} Select one: a. java.awt.event b. JFrame c. MouseEvent d. MouseListener e. this

e. this


संबंधित स्टडी सेट्स

SENTENCES : Fragments, identifying

View Set

college personal finance semester test

View Set

Chapter 4, 5 & 6 Nutrition- Kelly Owen

View Set

4.5 Maritime Empires Maintained and Developed

View Set

Choisissez (entourez) la bonne réponse

View Set

Mengenal Teks Eksplanasi - BI/G8

View Set