Java OCA OCP Practice Question 1554

Question

What will the following program print?

public class Main{
  static String str;
  public static void main (String [] args){
     System.out.println(str);
  }
}

Select 1 option

  • A. It will not compile.
  • B. It will compile but throw an exception at runtime.
  • C. It will print 'null' (without quotes).
  • D. It will print nothing.
  • E. None of the above.


Correct Option is  : C

Note

All member fields, static and non-static, are initialized to their default values.

Objects are initialized to null, numeric types to 0 (or 0.0 ) and boolean to false.




PreviousNext

Related