Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Multiple Choice Identify the letter of the choice that best completes the statem

ID: 3633868 • Letter: M

Question

Multiple Choice
Identify the letter of the choice that best completes the statement or answers the question.

____ 1. Which of the following is a valid statement?
a. String name("Doe"); c. String name = "Doe";
b. String ("Doe"); d. name = new String;


____ 2. There are ____ types of methods in a class.
a. 2 c. 4
b. 3 d. 5


____ 3. What happens when JOptionPane.WARNING_MESSAGE is chosen as the messageType parameter?
a. No icon is displayed in the dialog box.
b. An X is displayed in the dialog box.
c. A question mark is displayed in the dialog box.
d. An exclamation point is displayed in the dialog box.


____ 4. What does <= mean?
a. less than c. less than or equal to
b. greater than d. greater than or equal to


____ 5. Which of the following will cause a semantic error, if you are trying to compare x to 5?
a. if (x == 5) c. if (x <= 5)
b. if (x = 5) d. if (x >= 5)


____ 6. Which of the following is NOT a relational operator in Java?
a. != c. <<
b. <= d. >=


____ 7. The method compareTo belongs to which class?
a. Math c. Integer
b. String d. Double


____ 8. Consider the following statements.

String str1 = "car";
String str2 = "cars";

What is the value of the expression str2.compareTo(str1)?
a. a positive integer c. 0
b. a negative integer d. a boolean value


____ 9. Which of the following is not a logical operator?
a. ! c. !=
b. || d. &&


____ 10. Which of the following will cause a syntax error?
a. (0 < num) && (num < 12) c. 0 < num && num < 12
b. 0 < num < 12 d. num > 0 && num < 12


____ 11. After the execution of the following code, what will be the value of num if the input value is 4? (Assume that console is a Scanner object initialized to the standard input device.)

int num = console.nextInt();

if (num > 0)
num = num + 10;
else
if (num >= 5)
num = num + 15;
a. 4 c. 14
b. 5 d. 15


____ 12. What is the output of the following code fragment?

int x = 10;
if (x > 15)
x = 0;
System.out.println(x);
else
System.out.println(x + 5);
a. 0 c. 10
b. 5 d. None of these


____ 13. Suppose x and y are int variables. Consider the following statements.

if (x > 5)
y = 1;
else if (x < 5)
{
if (x < 3)
y = 2;
else
y = 3;
}
else
y = 4;

If the value of y is found to be 2, what is a possible value of x?
a. 2 c. 5
b. 3 d. 6


____ 14. What is the output of the following Java code?

int x = 55;
int y = 5;

switch (x % 7)
{
case 0:
case 1: y++;
case 2:
case 3: y = y + 2;
case 4: break;
case 5:
case 6: y = y – 3;
}

System.out.println(y);
a. 2 c. 8
b. 5 d. None of these


____ 15. Which modifier is used to specify that a method cannot be used outside a class?
a. public c. static
b. abstract d. private


____ 16. How can a method send a primitive value back to the caller?
a. It cannot send primitive values back to the caller
b. By using the return statement
c. By assigning the value to one of its parameters
d. It can call its caller with the value


____ 17. Which of the following identifiers is NOT visible in block three?
a. z (before main) c. main
b. t (before main) d. local variables of method two


____ 18. What is the function of the reserved word class?
a. It defines a data type and allocates memory.
b. It defines only a data type; it does not allocate memory.
c. It acts as a modifier.
d. It has no function.


____ 19. How many constructors can a class have?
a. 0 c. 2
b. 1 d. Any number




____ 20. Which of the following would be a default constructor for the class Clock shown in the figure above?
a. public Clock(){ setTime(0, 0, 0); }
b. public Clock(0, 0, 0) { setTime(); }
c. public Clock(0) { setTime(0); }
d. private Clock(10){ setTime(); }



Explanation / Answer

Dear,
1) String name = "Doe";
2) 2
3) d. An exclamation point is displayed in the dialog box.
4) less than or equal to
5) b. if (x = 5)
6) <<
7)b. String
8) a. a positive integer
9)c. !=
10)b. 0 < num < 12
11)c. 14
12) a. 0
13) a. 2
14) a. 2
15 d. private

16) b. By using the return statement
18)b. It defines only a data type; it does not allocate memory.
19) d. Any number
20)a. public Clock(){ setTime(0, 0, 0); }

Hope this will help you..