jQuery in Action, 3rd edition
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: http://aspose.com/file-tools
subject: inheritance - flow
It's not a secret anymore!