Hi,
In Khalid Mughal
Java certification book, it is given that;
"A subclass in another package can only access protected members in the superclass via references of its own type or a subtype."
The example given to eplain this fact is as follows:
package A;
public class SuperclassA
{
protected int SuperclassVarA;
protected void superclassMethodA()
{
}
}
package B;
import A.*;
public class SubclassB extends SuperclassA
{
SuperclassA objRefA = new SubclassB();
SubclassB objRefB = new SubclassB();
void SubclassMethodB()
{
objRefB.superclassMethodA(); //Valid
objRefA.superclassMethodA(); //Invalid
}
}
Can anyone pls explain why objRefA.superclassMethodA(); is invalid.
Rads