import java.sql.Date; public class ValueTest8 { /** * @author:lixh * * 返回一个引用对象的访问器,应该用clone() */ public static void main(String[] args) { // TODO Auto-generated method stub ValueTest8 v1 = new ValueTest8(); Date d1 = v1.getDate(); d1.setTime(System.currentTimeMillis()); System.out.println(d1); System.out.println(v1.getDate()); int y = v1.getSalary(); y=5; System.out.println(v1.getSalary()); System.out.println(y); } private int salary; private Date date = Date.valueOf("2017-12-12"); public ValueTest8(){ } public ValueTest8(int x){ this.salary = x; } public int getSalary() { return this.salary; } /*public Date getDate() { return date; }*/ public Date getDate() { return (Date) date.clone(); } public void setDate(Date date) { this.date = date; } }