• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inheritance - flow

 
Mark Henryson
Ranch Hand
Posts: 200
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 198
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println(new Q13(3).i); //line 1

What the above statement implies?
 
Lee Diego
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic