可以,刚才怀疑方法内部类是否可以,试了试,没问题
public class Outer {
private String s = "niaho";
public void method() {
class Inter {
void print() {
System.out.println(s);
}
}
Inter inter = new Inter();
inter.print();
}
public static void main(String[] args) {
Outer outer = new Outer();
outer.method();
}
} |