File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheritance - flow" Watch "inheritance - flow" New topic
Author

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:


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
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
Greenhorn

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