please first check out the following code:
//file:/aaa/A.java
package aaa;
class A{
protected int protectedVariable;
}
//file:/bbb/B.java
package bbb;
import aaa.A;
class B extends A{
public static void main(
String[] args){
A a = new A();
B b = new B();
a.protectedVariable = 30;//illeage,but why?
b.protectedVariable = 30;//perfectly legal,and why?
}
}
we know protected modified methods and variables have both inheritance visibility(i am not sure whether this saying is suitable,if not please correct me) and package visibility,but what kind of principle does the above code illustrate. THX!