posted 13 years ago
Hi guys!
Could you please help me with my concern about inheritance of private members. It is stated that: "A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass."
I don't understand why the private variable isn't inherited while you are able to access it using an inherited public method?
For example, we have two classes:
Now let's create two objects:
For both of these objects I can use:
So I can get private variable with bObj. So the variable is inherited, otherwise how did I get an access to it?
I realise that child object contains an object of parent class in it... so I'm just confused about the statement "a subclass doesn't inherit the private members of its parent class". Can you clarify this for me please?
Thank you!