why private property can be inherited in this program?
Joined: Mar 15, 2008
the code is placed in a physical file named classA.java.
property see in class A is private, so I suppose B cannot inherit this property, but when class C call b.getSee(), value "abc" can be retrieved, why would this happen?
class scope is the solution of your problem...when we call getSee() method this is called directly because of pubic...but this public method checked by the compiler in parent class..so compiler call that method...after that cursor is in A class scope, so we can access private members easily in same class....
Thakur Sachin Singh wrote:B class doesn't have see property...this is not inherited from super class that by compiler error bacause in B class there is no visibility of see property.
Well, it does have the property. It just doesn't know it has it.Through reflection you can still get its value using an instance of class B.
Hate to split hairs -- as it makes me feel like a lawyer. Technically, the property isn't part of Class B, as there is no definition of it. However, the property is part of all Class B instances, as instances have components defined by their super classes.