当前位置: 代码迷 >> Java Web开发 >> 请求帮忙解释代码
  详细解决方案

请求帮忙解释代码

热度:211   发布时间:2010-11-10 13:13:29.0
请求帮忙解释代码
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;
这段语句是啥意识?
搜索更多相关主题的帖子: 代码  请求  解释  

----------------解决方案--------------------------------------------------------
重写clone方法 然后返回一个person对象 有问题么?

----------------解决方案--------------------------------------------------------
回复 2楼 maxliz
不是这意识吧
----------------解决方案--------------------------------------------------------
是这个意思的
----------------解决方案--------------------------------------------------------
路过、、、、
----------------解决方案--------------------------------------------------------
2#如是说
----------------解决方案--------------------------------------------------------
  相关解决方案