Punit Singh wrote:
This is confusing. As far as i know Protected means Available to subclasses even outside Package. If outside pacakage then we can access the protected members via inheritance. Thats what i am doing. Isn't it? Then why compiler error?
This means you can use protected member using instance of subclass only, not the instance of superclass.
As protected member is inheritable, you can use thinking it as a member of subclass, but not a member of superclass if there is a package difference.
subclassinstance.protectedmember;//ok as subclass has this member via inheritence.
superclassinstance.protectedmember;//compiler error as accessing super class protected member outside the package.