java Cloneable的设置应用

ublic class day5 {
    public static void main(String[] args) {
        Stuent stuent1 = new Stuent(1,"baizi",18,"男");
        Stuent stuent2=null;
        try {
            stuent2=(Stuent) stuent1.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        System.out.println(stuent2.getName());
    }
}
class Stuent implements Cloneable{
    private  int id;
    private  String  name;
    private  int age;
    private  String gender;

    public Stuent() {
    }

    public Stuent(int id, String name, int age, String gender) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    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 int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

你可能感兴趣的:(java,java,原型模式,开发语言)