I'm preparing for OCPJP and when reading the first chapter of
SCJP Sun Certified Programmer for
Java 6 Guide, I've got:
"The subclass can see the protected member
only through inheritance."
Would this first statement be replaced by
"Subclasses belonging to other packages can access protected members only through inheritance." (this statement comes from:
the scjp handbook)
Because, when writing some code for
testing, I'm getting something a bit
confusing considering the first statement. Roo and Cloo are in the same package. So I declared doRooThings method from Roo class as protected and I extend Roo in Cloo class. So in testCloo method from Cloo class, I invoke the method from a reference to Roo and invoke from inheritance. I think that invoking from a reference should produce a compilation error (considering the first statement from book).
Could someone give me some help to understant it?
Roo class with doRooThings declared with protected modifier.
Cloo class extending Roo and using doRooThings from Roo instance reference.