This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes inheritance - flow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheritance - flow" Watch "inheritance - flow" New topic

inheritance - flow

Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
I have slighlty confused with the flow of the below pgm:
Please someone explain it:

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
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
System.out.println(new Q13(3).i); //line 1

What the above statement implies?
Lee Diego

Joined: Aug 16, 2005
Posts: 11

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).

could perhaps be written a bit easier with
I agree. Here's the link:
subject: inheritance - flow
Similar Threads
Why the result of printing out the not-letter chars to console is different from to applets
super constructor
Question about Interfaces..