我已经开始为OCJP7考试做准备了,我发现这一章似乎非常复杂。
假设我有以下代码:
class Outer1{
interface InnerInterface{
String x = "test";
}
class InnerClass{
String x = "test";
}
}
class Outer2{
static interface NestedInterface{
String x = "test";
}
static class NestedClass{
String x = "test";
}
}
class Main{
public static void main(String [] args){
String s1 = Outer1.InnerInterface.x;
String s2 = new Outer1().new InnerClass().x;
String s3 = Outer2.NestedInterface.x;
String s4 = new Outer2.NestedClass().x;
}
}
你能告诉我为什么我们可以以相同的方式访问 Outer1.InnerInterface.x
和 Outer2.NestedInterface.x
吗?内部接口默认是静态的吗?我正在尝试建立一些联系来使它们更清晰。