Added: 3 years ago
From: Zantorc
Views: 1,209
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (4)

Sign In or Sign Up now to post a comment!
  • If class Test extends Top.Nest1, does it also inherit all of class Top members?

    I'm looking at the line "int x = (new Top()).j;", and I have trouble understanding it, the only explanation would be that the it does inherit all of the above.

    I ask this because "j" is marked as private in class Top, and it is being accessed from outside the Top class.

    Thank you!

  • You're right both tp.j and (new Top()).j will fail - I'm trying to show too much on one diagram. If j wasn't private it would work. I made it private so I could show access to private fields in Nest1.

  • Thank you!

    So, the conclusion would be that when class Test extends Top.Nest1, it doesn't inherit all of class Top members, only Nest1's?

  • Yes. When you're in a class there are 2 direction you can go to look for a member. Up through the inheritance tree or outwards through enclosing classes. (You can't go up a bit and then out).

    Originally I had static int k; in Top, but I took it out so I could put in more text and changed k in Test to be j :-( The thing I really wanted to show in Test, was the use of a null reference to get a static field doesn't give a null pointer exception - that's surprising.

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more