我有一个问题属于 Java 中的多级继承。所有三个类都在同一个包中
我有 A 类:
public class A {
protected int x;
}
public class B extends A {
public void doSomething {
// x is visible.agreed, as it is a direct subclass of A
}
}
public class C extends B {
public void doSomething {
// x is still visible, how come? I mean it is at the 2nd level
// I am confused why?
}
}
它有什么意义吗?还是我们必须默认采取的行为?