Java Tutorial 20.02: Static member classes

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
1,195
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Nov 7, 2008

Java Tutorial 20: (part 2 of 5)Nested Classes: Static member classes in Java (AKA top level nested classes). See next tutorial for other nested classes.

Category:

Education

Tags:

License:

Standard YouTube License

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (Zantorc)

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

see all

All Comments (4)

Sign In or Sign Up now to post a comment!
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