8. Which of the following method names adheres to the Java naming convention standards?
(a) is_empty (b) IsEmpty
(c) is-empty (d) isEmpty
9. Consider the following Java code segment. public class IQ {
public int getIQ(String s) {
return 50; } }
If object p is an instance of class IQ, which of the following is a Java statements that will not generate a compilation error? (a) int c = p.getIQ(\(b) String s = IQ.getIQ(p);
(c) getIQ.p(\
(d) IQ x = getIQ(\
10. Which of the following statements is true about methods in Java?
I. II. III.
Every method must be declared public.
Every method must accept at least one parameter. Every method must return a value.
(a) I, II, and III
(b) II and III only (c) none of them
(d) III only
11. In Java, the initial values of method parameters are set by
(a) arguments of the invoking message (b) access control
(c) accessor methods
(d) initialization statements
12. Which of the following is (are) true of instance variables in
Java?
I.
II. III.
Their declarations must appear at the end of a class definition.
Their declarations must appear outside of all method definitions.
Instance variables must be declared.
(a) I, II, and III (b) I and II only
(c) II and III only (d) III only
Take Assessment: Multiple-Choice Quiz 6
1. In Java, non-sequential execution of code is achieved by using
_____ statements.
(a) control (b) ordering
(c) branching (d) concurrent
2. Which of the following Java statements assigns the bigger of x and
y to the variable max. I. II. III.
if (x > y) max = x; else max = y;
if (y - x <= 0) max = x; else max = y; max = x; if (x < y) max = y;
(a) III only (b) I only
(c) I and II only (d) I, II and III
3. Which of the following data types is a Java primitive type?
(a) class (b) void
(c) applet (d) boolean
4. The type of the number 2.0 in Java can be
(a) double (b) int
(c) boolean (d) Panel
5. Each Java program is made up of _____ class.
(a) exactly one (b) at least one
(c) a constructor (d) at most one
6. Which of the following is not a valid Java identifier?
(a) 2square (b) money_bag
(c) myName (d) value4
7. How many times will this loop execute?
int y = 1;
int i;
for (i = 10; i < 0; i = i - 1) y = i + 2; (a) 9 (b) 10
(c) 0 The loop test is false because i is not less than 0 (d) 11
8. When the following code segment is executed, how many times will
the string \
for (int i = 0; i < 6; i++)
for (int j = i; j < 6 - i; j++) System.out.print(\(a) 21 (b) 36
(c) 12 (d) 11
9. What is the value of variable product at the end of any execution
of the following Java program segment?
int i = 3;
int product = 1;
while (i != 0) {
product = product * i;
i = i - 1; } (a) 1 (b) 6
(c) 0 (d) 3
10. Which of the following Java constructs loop infinitely?
I. II. III.
while (true) i = 0; while (false) i = 1; while (!false) i = 0;
(a) I, II and III (b) I only
(c) III only (d) I and III only
11. In Java, for primitives, the assignment operator is the symbol
_____ and the equality operator is the symbol _____.
(a) =, == (b) :=, =
(c) =, equals() (d) ==, =
12. In Java, the operator \
purposes?
I.
Addition of two integers