Q1. You are writing a method that is declared not to return a value. Which two are permitted in
the method body?
A. omission of the return statement
B. return null;
C. return void;
D. return;
Answer: AD
Q2. Given:
A. a, e i, o
B. a, e o, o
C. e, e I, o
D. e, e o, o
Answer: D
Q3. A method doSomething () that has no exception handling code is modified to trail a method that throws a checked exception. Which two modifications, made independently, will allow the program to compile?
A. Catch the exception in the method doSomething().
B. Declare the exception to be thrown in the doSomething() method signature.
C. Cast the exception to a RunTimeException in the doSomething() method.
D. Catch the exception in the method that calls doSomething().
Answer: AB
Q4. public class Two {
public static void main(String[] args) {
try {
doStuff();
system.out.println("1");
}
catch {
system.out.println("2");
}}
public static void do Stuff() {
if (Math.random() > 0.5) throw new RunTimeException(); doMoreStuff();
System.out.println("3 ");
}
public static void doMoreStuff() {
System.out.println("4");
}
}
Which two are possible outputs?
A. 2
B. 4 3 1
C. 1
D. 1 2
Answer: AB
Q5. class Overloading {
int x(double d) {
System.out.println("one");
return 0;
}
String x(double d) {
System.out.println("two");
return null;
}
double x(double d) {
System.out.println("three");
return 0.0;
}
public static void main(String[] args) {
new Overloading().x(4.0);
}
}
What is the result?
A. One
B. Two
C. Three
D. Compilation fails.
Answer: D
Q6. Given:
What is the result?
A. 1 1 1
B. 1 2 3
C. 2 3 4
D. Compilation fails
E. The loop executes infinite times
Answer: D
Q7. Which code fragment cause a compilation error?
A. flat flt = 100F;
B. float flt = (float) 1_11.00;
C. float flt = 100;
D. double y1 = 203.22; floatflt = y1
E. int y2 = 100; floatflt = (float) y2;
Answer: B
Q8. What is the result?
A. sc: class.Object asc: class.AnotherSampleClass
B. sc: class.SampleClass asc: class.AnotherSampleClass
C. sc: class.AnotherSampleClass asc: class.SampleClass
D. sc: class.AnotherSampleClass asc: class.AnotherSampleClass
Answer: D
Q9. for ( expr1 ; expr2 ; expr3 ) {
statement;
}
Which two statements are true?
A. This is not the only valid for loop construct; there exits another form of for loop
constructor.
B. The expression expr1 is optional. it initializes the loop and is evaluated once, as the loop
begin.
C. When expr2 evaluates to false, the loop terminates. It is evaluated only after each
iteration through the loop.
D. The expression expr3 must be present. It is evaluated after each iteration through the
loop.
Answer: BC
Q10. The catch clause argument is always of type__________.
A. Exception
B. Exception but NOT including RuntimeException
C. Throwable
D. RuntimeException
E. CheckedException
F. Error
Answer: C