0
What is the output of the following Java program?

Open 1 Answers 20 Views Education
What is the output of the following Java program?

class Test   

{  

    int i;   

}  

public class Main   

{  

    public static void main (String args[])   

    {  

        Test test = new Test();   

        System.out.println(test.i);  

    }  

}

1 Answer

0

What is the output of the following Java program?

class Test   

{  

    int i;   

}  

public class Main   

{  

    public static void main (String args[])   

    {  

        Test test = new Test();   

        System.out.println(test.i);  

    }  

}  

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.

by (53.7k points)
...