Java OCA OCP Practice Question 2513

Question

Which of the following statements is true when the code is run with java Main?

1:    public class Main { 
2:       public static void main(String [] args) { 
3:          Integer x = 10; 
4:          x++; 
5:          assert x == null && x >= 0; 
6:          System.out.println(x); 
7:       } 
8:    } 
  • A. Line 3 generates a compiler error.
  • B. Line 4 generates a compiler error.
  • C. Line 5 generates a compiler error.
  • D. Line 5 throws an AssertionError at runtime.
  • E. The output is 10.
  • F. The output is 11.


F.

Note

The code compiles due to autoboxing.

The command line does not enable assertions, so D cannot happen.

Line 6 executes and prints out 11, so the answer is F.




PreviousNext

Related