注册 登录
编程论坛 J2EE论坛

请求帮忙解释代码

lmh814645654 发布于 2010-11-10 13:13, 954 次点击
class Person implements Cloneable{   //实现
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public void display(){
        System.out.println("name :"+name+"\tage:"+age);
    }
    protected Object clone(){
        Person p = null;
        try {
            p = (Person) super.clone();
        } catch (CloneNotSupportedException ex) {
           
        }
        return p;
    }
}
public class TestKL {
    public static void main(String[] args) {
        Person p1 = new Person("tom",18);
       Person p2 = (Person)p1.clone();
       System.out.println(p1.equals(p2));
    p2.setAge(18);
        p1.display();
       p2.display();
    }
}
请问这程序中的: protected Object clone(){
        Person p = null;
        try {
            p = (Person) super.clone();
        } catch (CloneNotSupportedException ex) {
           
        }
        return p;
这段语句是啥意识?
5 回复
#2
maxliz2010-11-11 22:04
重写clone方法 然后返回一个person对象 有问题么?
#3
lmh8146456542010-11-12 14:06
回复 2楼 maxliz
不是这意识吧
#4
LmissM2010-12-06 22:43
是这个意思的
#5
it33142011-01-03 20:42
路过、、、、
#6
缘吇弹2011-02-10 22:40
2#如是说
1