Java OCA OCP Practice Question 2518

Question

What is the result of executing the following code? (Choose all that apply.)

String line; 
Console c = System.console(); 
if ((line = c.readLine()) != null) 
   System.out.println(line); 
  • A. The code runs without error but prints nothing.
  • B. The code prints what was entered by the user.
  • C. An ArrayIndexOutOfBoundsException might be thrown.
  • D. A NullPointerException might be thrown.
  • E. An IOException might be thrown.
  • F. The code does not compile.


B, D.

Note

Option B is correct because this is the right way to read data from the Console.

Option D is also correct.

If there is no console available, a NullPointerException is thrown.

The read method does not throw an IOException.




PreviousNext

Related