What is the output of the following Java program no. 5?

  1. class Test
  2. {
  3.     int i;
  4. }
  5. public class Main
  6. {
  7.     public static void main (String args[])
  8.     {
  9.         Test test = new Test();
  10.         System.out.println(test.i);
  11.     }
  12. }

The output of the program is 0 because the variable i is initialized to 0 internally. As we know that a default constructor is invoked implicitly if there is no constructor in the class, the variable i is initialized to 0 since there is no constructor in the class.