Private members in Java inheritance -


i told java subclass can inherit members of superclass. mean private members? know can inherit protected members.

can explain me. totally confused.

no, private member not inherited because scope of private member only limited class in defined. public , protected member inherited.

from java documentation,

private members in superclass

a subclass does not inherit private members of parent class. however, if superclass has public or protected methods accessing private fields, these can used subclass. nested class has access private members of enclosing class—both fields , methods. therefore, public or protected nested class inherited subclass has indirect access of private members of superclass.

from jls,

members of class that declared private not inherited subclasses of class. members of class declared protected or public inherited subclasses declared in package other 1 in class declared.

a useful link : does subclasses inherit private fields?


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -