I have an instance variable in the class Avo, package ger1, with protected modifier.
package ger1;
public class Avo {
protected int i = 1;
}
Then I have a class Pai which is in package ger2, extends Avo and accesses the variable by instance, so far normal...
package ger2;
public class Pai extends Avo {
public Pai() {
i++
}
}
But Kathy Sierra's book says of the protected member, "Once the subclass-outside-the-package inherits the protected member, that member (as inherited by the subclass) becomes private to any code outside the subclass, with the exception of subclasses of the subclass."
But if i try to access the member through instance of class Pai it's allowed! However the Filho class must be in the same package of Avo. Why this? It's normal?
package ger1;
import ger2.Pai;
public class Filho {
public Filho() {
Pai pai = new Pai();
pai.i++;
}
}