日期:2014-05-20 浏览次数:20642 次
import javax.swing.*; import java.util.*; import java.math.*; import java.util.Date; //package java.util.*; public class CloneTest { public static void main(String[] args) { Employee e1 = new Employee(); Employee e2 = new Employee(); e1.age = 1; e2.age = 2; SWAP.swap(e1, e2); System.out.println(e1.age); System.out.println(e2.age); } } class SWAP { public static void swap(Employee a1, Employee a2) { Employee tmp; tmp = a1; a1 = a2; a2 = tmp; } } class Employee { public int age; public Employee() { // System.out.println("Employee::Employee()"); } public static void main(String[]args) { // System.out.println("Employee::main"); } }
package test; public class Test1 { /** *@Description: *@author:zhangjp *@Parameter: *@time:2012 Jul 30, 2012 8:47:12 AM */ public static void main(String[] args) { int n = 20; User u = new User(18,"zhangsan"); System.out.println(u); change(u, n); System.out.println(u); System.out.println(n); } public static void change(User u,int i){ i = 25; u.setId(25); } } package test; public class User { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public User(int id, String name) { super(); this.id = id; this.name = name; } @Override public String toString() { return "u.id="+id+" "+"u.name="+" "+name; } }
------解决方案--------------------