public class SwallowClone
{
public static void main(String args[]) throws CloneNotSupportedException
{
SwallowTest test=new SwallowTest();
test.setAge(20);
test.setName("lucy");
SwallowTest swallow=(SwallowTest)test.clone();
System.out.println(swallow.getAge()+" "+swallow.getName());
}
}
class SwallowTest implements Cloneable
{
private int age;
private String name;
public Object clone() throws CloneNotSupportedException
{
return super.clone();
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
浅clone的运用
最新推荐文章于 2018-05-19 18:49:59 发布