《引用传递经典三道题.docx》由会员分享,可在线阅读,更多相关《引用传递经典三道题.docx(3页珍藏版)》请在金锄头文库上搜索。
1、引用传递经典三道题public class Messagel (private int num=10 ;Messagel(int num)(this.num = num ;)public void setNum(int num)(this.num = num;public int getNum()(return num;)测试类:public class Testi (public static void main(String args) (Messagel msg = new Messagel(30); fc/(msg);引用传递System.out.printIn(msg.getNum(
2、);)public static void fun(Messagel temp)(temp.setNum(100);/*运行结果:100* 2016-10-04 23:08:46*/二,public class Message (private String info = nihao;Message0(String info)(this.info = info;)public void setInfo(String info)( this.info = info ;public String getlnfo()(return info;) 测试类;public class Test0 (pub
3、lic static void main(String args) (Message msg = new Message0(hell);所(msg);System.out.printIn(msg.getInfo();)public static void fun(Message0 msg)( msg, setIn千o(word);)/*运行结果:word* 2016-10-04 22:55:59*/public class Messag2 public static void main(String args) (String msg = Hell;伽(msg);System.out.printIn(msg);public static void fun(String temp)(temp = word;/*运行结果:Hell;* 2016-10-04 23:18:17*/