Java OCA OCP Practice Question 966

Question

What happens when you try to compile and run the following code?

public class Main { 
     static String s; 
     public static void main(String[] args) { 
       System.out.println(">>" + s + "<<"); 
     } 
} 
  • A. The code does not compile
  • B. The code compiles, and prints out >><<
  • C. The code compiles, and prints out >>null<<


C.

Note

The code compiles without error.

At static initialization time, s is initialized to null.




PreviousNext

Related