Results 1 to 5 of 5
  1. #1
    Joza is offline Member
    Join Date
    Jan 2012
    Posts
    4
    Rep Power
    0

    Default Inheriting private stuff from a Superclass ... let's settle this once and for all!

    I'm sure this has been asked a million time, but everywhere I look, people seem to over-complicate the answer ... so I'm STILL confused.

    Do subclasses inherit the private fields of the superclass? That is, if the super class has a private variable called A, does the subclass get its OWN COPY of that variable called A, which is NOT the same variable, just has the same name?

    Or, are private fields just not inherited AT ALL? If I want a private variable in my subclass just like in the superclass, I must explicitly define it in the subclass code?

  2. #2
    Lowest0ne is offline Member
    Join Date
    Apr 2012
    Posts
    21
    Rep Power
    0

    Default Re: Inheriting private stuff from a Superclass ... let's settle this once and for all

    The sub-class "is a" super-class, there is only one variable "A" per instance.

  3. #3
    Joza is offline Member
    Join Date
    Jan 2012
    Posts
    4
    Rep Power
    0

    Default Re: Inheriting private stuff from a Superclass ... let's settle this once and for all

    Quote Originally Posted by Lowest0ne View Post
    The sub-class "is a" super-class, there is only one variable "A" per instance.
    Sorry, but that's not answering my question at all...

  4. #4
    Lowest0ne is offline Member
    Join Date
    Apr 2012
    Posts
    21
    Rep Power
    0

    Default Re: Inheriting private stuff from a Superclass ... let's settle this once and for all

    Or, are private fields just not inherited AT ALL? If I want a private variable in my subclass just like in the superclass, I must explicitly define it in the subclass code?
    This would make the super class useless.

    Do subclasses inherit the private fields of the superclass? That is, if the super class has a private variable called A, does the subclass get its OWN COPY of that variable called A, which is NOT the same variable, just has the same name?
    The sub class extends the super class, there is no "OWN COPY", there is only one instance.

    Edit: or perhaps post some code to explain what confuses you.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 3
    Last Post: 11-22-2011, 06:51 AM
  2. Having trouble with inheriting constructor from superclass
    By coasterguy10 in forum New To Java
    Replies: 3
    Last Post: 10-20-2011, 06:07 AM
  3. Inheriting two kinds of Lists into one Class
    By rsiddharth in forum New To Java
    Replies: 22
    Last Post: 12-26-2010, 04:39 PM
  4. How is this dog inheriting a bark?
    By fresh83 in forum New To Java
    Replies: 3
    Last Post: 07-05-2010, 02:33 AM
  5. Replies: 7
    Last Post: 06-28-2010, 08:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •