这是内部类的程序
class One{
int i;
class Two{
int j;
int funTwo(){
int result = i+j;
return result;
}
}
}
运行程序1
public class Test{
public static void main(String args []){
One one = new One();
One.Two two =new One().new Two();
one.i = 5;
two.j = 6;
int result = two.funTwo();
System.out.println(result);
运行程序2
public class Test{
public static void main(String args []){
One one = new One();
One.Two two=one.new Two();
one.i = 5;
two.j = 6;
int result = two.funTwo();
System.out.println(result);
结果应该是一样的,可为什么第一个程序运行的结果是6. 第二个是11呢 |