in Education by
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 votes
by

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.

Related questions

0 votes
    What is the output of the following Java program? public class Test { Test(int a, int b) { System.out.println("a = "+a+" b = "+ ... 10; byte b = 15; Test test = new Test(a,b); } }...
asked Nov 19, 2020 in Education by Editorial Staff
0 votes
    What is the output of the following Java program? What is the output of the following Java program? class Test { public static ... ) { System.out.println("Hello Javatpoint"); } } }...
asked Nov 17, 2020 in Education by Editorial Staff
0 votes
    What is the output of the following Java program? class Test { public static void main (String args[]) { System.out.println(10 ... * 20); } } The output of the above code will be...
asked Nov 17, 2020 in Education by Editorial Staff
0 votes
    What is the output of the following Java program? class Test { public static void main (String args[]) { System.out.println(10 ... ; System.out.println("Javatpoint" + 10 + 20); } }...
asked Nov 17, 2020 in Education by Editorial Staff
0 votes
    What will be the output of the following Java program? public class Test { public static void main( ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
0 votes
    What is the output of the following Java program? class Test { int test_a, test_b; Test(int a, int b) { test_a = a; ... (); System.out.println(test.test_a+" "+test.test_b); } }...
asked Nov 19, 2020 in Education by Editorial Staff
0 votes
    What will be the output of the following Python program? z=set('abc') z.add('san') z.update(set(['p', 'q'] ... ;, ‘c’, [‘p’, ‘q’], ‘san}...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc ... (id(q) == foo(q)) a) Error b) None c) False d) True...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? z=set('abc') z.add('san') z.update(set(['p', 'q'] ... ;, ‘c’, [‘p’, ‘q’], ‘san}...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc ... (id(q) == foo(q)) a) Error b) None c) False d) True...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What is the output of the following program? 3 . #include using namespace std; struct Time { int hours; int ... 20000 D. O 15000 Select the correct answer from above options...
asked Dec 27, 2021 in Education by JackTerrance
0 votes
    What is the output of the following program? 3 . #include using namespace std; struct Time { int hours; int ... 20000 D. O 15000 Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
0 votes
    What will be the output of the following program? public class MyFirst { public static void main(String[ ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
...