MY mENU


Thursday 9 February 2012

Can we access Private members of superclass in sub class?


No, A SubClass does not inherit the Private Members of its SuperClass.

But indirectly we can, how means see bellow :

- If the SuperClass has public or protected methods for accessing its Private Fields, these we can also use in SubClass.

- A Nested Class has access to all the Private Members (fields and methods) of its enclosing Class. Therefore, a public or protected Nested Class inherited by our SubClass has indirect access to all of the Private members of the SuperClass.

No comments:

Post a Comment