我试图理解为什么子类无法访问超类中的受保护变量?
package pack1;
public class Parent {
protected int r;
public int s;
}
package pack2;
import pack1.Parent;
public class Child extends Parent {
public static void main(String[] args) {
Parent obj = new Child();
obj.r = 2; //r is not accessible here. It becomes accessible when I make it static.
obj.s = 3; //s is accessible.
}
}