复制代码
- //:Alias1.java
- //Aliasingtwohandlestooneobject
- publicclassAlias1{
- inti;
- Alias1(intii){i=ii;}
- publicstaticvoidmain(String[]args){
- Alias1x=newAlias1(7);
- Alias1y=x;//Assignthehandle
- System.out.println("x:"+x.i);
- System.out.println("y:"+y.i);
- System.out.println("Incrementingx");
- x.i++;
- System.out.println("x:"+x.i);
- System.out.println("y:"+y.i);
- }
- }///:~
复制代码
- x:7
- y:7
- Incrementingx
- x:8
- y:8
复制代码
- //:Alias2.java
- //Methodcallsimplicitlyaliastheir
- //arguments.
- publicclassAlias2{
- inti;
- Alias2(intii){i=ii;}
- staticvoidf(Alias2handle){
- handle.i++;
- }
- publicstaticvoidmain(String[]args){
- Alias2x=newAlias2(7);
- System.out.println("x:"+x.i);
- System.out.println("Callingf(x)");
- f(x);
- System.out.println("x:"+x.i);
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |