Java OCA OCP Practice Question 1379

Question

How many times does this code print true?

import java.time.*; 
public class Main { 
   public void main(String[] args) { 
      System.out.println(new StringBuilder("asdf") 
          == new StringBuilder("asdf")); 
      System.out.println(3 == 3); 
      System.out.println("aaaa" == "aaaa"); 
      System.out.println(new int[0] == new int[0]); 
      System.out.println(LocalTime.now() == LocalTime.now()); 
   } /*  w w w. j  a v a2  s.c om*/
} 
  • A. None
  • B. One
  • C. Two
  • D. Three
  • E. The code does not compile.


A.

Note

The main() method is missing the static keyword.

Running this problem gives a runtime exception because the main() method is not properly declared.

Option A is the answer.

If this was fixed, the answer would be Option C because the int and String comparisons return true.




PreviousNext

Related