pandatoclone.java

来自「《Java与模式》一书的源代码」· Java 代码 · 共 45 行

JAVA
45
字号


package com.javapatterns.prototype.panda;

public class PandaToClone implements Cloneable
{
    private int height, weight, age;

    public PandaToClone(int height, int weight)
    {
        this.age = 0;
        this.weight = weight;
        this.height = height;
    }

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

    public int getAge()
    {
        return age;
    }

    public int getHeight()
    {
        return height;
    }

    public int getWeight()
    {
        return weight;
    }

    public Object clone()
    {
        PandaToClone temp = new PandaToClone(height, weight);
        temp.setAge(age);

        return (Object)temp;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?