首先程序错误,do是关键字,怎么可以用来定义函数名呢?编译不会通过。
修改如下:
- class Test
- {
- public static void main(String [] args)
- {
- int x =6;
- Test d =new Test();
- d.method(x);
- System.out.println("main:x ="+x);
- }
- void method(int x)
- {
- System.out.println("method:x ="+x);
- }
- }
复制代码
其次Test类里method方法定义的变量x是局部变量,函数运行完即从堆内存释放,和main方法中定义的x没有关系。
所以最后的输出结果:
method:x =6
main:x =6 |