public class Learning{
private String temp = "Outter";
private class Inner{
private String temp = "Inner";
public void print(){
String temp = "Inner function";
System.out.println(temp);
System.out.println(this.temp);
System.out.println(Learning.this.temp);
}
}
public static void main(String args[]){
Inner in = new Inner();//what's wrong with this line?
in.print();
}
}
答案 0 :(得分:1)
这一行
Inner in = new Inner();//what's wrong with this line?
使用没有外类的Inner。有两种方法可以解决这个问题
Inner in = new Learning().new Inner();
或制作课程static
private static class Inner {
虽然@flkes表示,但使用了外部实例。