Not D: Cannot be applied to given types. Line: Student s = new Student(123,"Fred", cs);

Q139. Given the code fragment:

What is the result?

A. Execution terminates in the first catch statement, and caught a RuntimeException is printed to the console.

B. Execution terminates In the second catch statement, and caught an Exception is printed to the console.

C. A runtime error is thrown in the thread "main".

D. Execution completes normally, and Ready to us. is printed to the console.

E. The code fails to compile because a throws keyword is required.

Answer: C

Q140. Given:

public class MyClass {

public static void main(String[] args) {

while (int ii = 0; ii < 2) {

ii++;

System.out.println("ii = " + ii);

}

}

}

What is the result?

A. ii = 1 ii = 2

B. Compilation fails

C. The program prints nothing

D. The program goes into an infinite loop with no output

E. The program goes to an infinite loop outputting: ii = 1 ii = 1

Answer: B

Explanation: The while statement is incorrect. It has the syntax of a for statement.

The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as:

while (expression) { statement(s) } The while statement evaluates expression, which must return a boolean value. If the expression evaluates to true, the while statement executes the statement(s) in the while block. The while statement continues testing the expression and executing its block until the expression evaluates to false.