【发布时间】:2012-11-05 22:07:51
【问题描述】:
我有一个问题属于 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?
}
}
它有什么意义吗?还是我们必须默认采取的行为?
【问题讨论】:
-
为什么不会会这样?
-
我在想这种方法只能在直接孩子之前完成,而不是孩子的孩子。我想我很困惑。是不是我把 C++ 和 Java 混在一起了?
标签: java class inheritance