Prithvi Sehgal wrote:Protected members, be it methods or variables are accessible through inheritance only, if the child class is outside the
package. For other classes, they are like, they don't even exist.
From the JavaDoc...
6.6.2 Details on protected Access
A protected member or constructor of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object.
Basically, in the case where a subclass wants to access the protected members of the super class, via a reference that is not the "this" reference -- and the subclass is not in the same package as the super class -- it can only do so, if it can be confirmed that the object IS-A sub class. This means that the superclass member can be accessed, if the referenced used is of a type subclass.
Henry