I have slighlty confused with the flow of the below pgm: Please someone explain it:
Options: a. Prints: 0 b. Prints: 3 c. Prints nothing d. Compilation error. e. An IllegalAccessError is thrown at runtime because 'i' is not accessible on line 1.
Hentay Duke
Ranch Hand
Joined: Oct 27, 2004
Posts: 198
posted
0
The answer is it prints 3. As for the flow, try putting sysout statements in each of the constructors and that will show you the flow.
Mark Henryson
Ranch Hand
Joined: Jul 11, 2005
Posts: 200
posted
0
System.out.println(new Q13(3).i); //line 1
What the above statement implies?
Lee Diego
Greenhorn
Joined: Aug 16, 2005
Posts: 11
posted
0
is the same as...
The point is that the Q13 object is created and the constructor is called, it just don't have a variable referencing it (you cannot get hold of that particular object after line 1).