Java OCA OCP Practice Question 1340

Question

What would be the result of attempting to compile and run the following piece of code?

public class Test {
   static int x;

   public static void main (String args[]) {  
            System.out.println("Value is " + x);  
   }  
}
  • A. The output "Value is 0" is printed.
  • B. An object of type NullPointerException is thrown.
  • C. An "illegal array declaration syntax" compiler error occurs.
  • D. A "possible reference before assignment" compiler error occurs.
  • E. An object of type ArrayIndexOutOfBoundsException is thrown.


A.

Note

The program compiles without error.

The default value of an uninitialized int variable is 0.




PreviousNext

Related