Question: What is the output of this Java program? class Test { int i=0; } class Main { public static void main(String args[]) { Test t;

What is the output of this Java program? class Test { int i=0; } class Main { public static void main(String args[]) { Test t; System.out.println(t.i); } } Answer Error

-----

class T { int t = 20; T() { t = 40; } } class Main { public static void main(String args[]) { T t1 = new T(); System.out.println(t1.t); } } Answer 40

-----------------

I need explanation >>why we get an error in the first one? and why we get ( 40) not (20) in the second one

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!