mysample
我有这样的代码,我需要InnerClass
在. 我尝试通过创建一个新对象来访问它,但我得到了.getInnerS()
NestedClass
InnerClass
java.lang.StackOverflowError
public class NestedClass{
private String outer = "Outer Class"; //NestedClass instance variable
NestedClass.InnerClass innerClass = new NestedClass.InnerClass();
void getOuterS(){
System.out.println(outer);
}
void getInnerS(){
System.out.println(innerClass.mysample);
}
static class InnerClass{
private String mysample = "Inner Class"; //InnerClass instance variable,
NestedClass a = new NestedClass();
void getIn(){
System.out.println(mysample);
}
void getOut(){
System.out.println(a.outer);
}
}
public static void main(String[] args){
NestedClass nestedClass = new NestedClass();
NestedClass.InnerClass nestedInner = new NestedClass.InnerClass();
nestedClass.getOuterS();
nestedClass.getInnerS();
nestedInner.getIn();
nestedInner.getOut();
}
}