Hi All,
I am a bit confused about access of protected members through inheritance. I know that protected members can be accessed through inherintance and reference if the access is done in the same package. When accessing through an outside package, access can only be granted through inheritance.
I am following the
SCJP Study Guide by Kathy Sierra and Bert Bates, and I have typed the examples in Figure 1-4 on page 37. Here they are:
---------------------------------------------
package a;
public class SportsCar {
static protected void goFast() {
System.out.println("Package a protected goFast");
}
public void doStuff(){
goFast();
}
}
--------------------------------
Second file:
--------------------------------
package b;
import a.SportsCar;
public class Convertible {
public void doMore(){
goFast();
}
}
---------------------------------
The compiler shows an error on the second file line goFast(); saying it is undefined
The book says that it should work, but it is not working
Also, to use the goFast method through inheritance in another class part of package (a), I had to make the goFast method static but I don't know why this is?
Thanks for your help.
marifer514