4-3 访问器,修改器

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;
    }
    
}

posted @ 2018-01-04 23:37  aLa神灯  阅读(242)  评论(0编辑  收藏  举报