考虑以下代码段。
package breakoop;
public class BreakOOP {
public static class A{
private int a;
}
public static class B extends A{
public int f(){
return super.a;
}
}
public static void main(String[] args) {
B b = new B();
System.out.println(b.f());
}
}
A
该示例仅在并且B
被封装在BreakOOP
类中时才编译。
这似乎违背了 OOP 的一些基本概念。有人可以解释为什么会编译吗?其背后的原因是什么?