按照书上的说法,只要在类声明中加入implements Cloneable就
可以调用默认的Clone()方法了。但下面的代码编译不能通过,请
帮忙看看,谢谢了。public class Cat implements Cloneable{
public static void main(String[] args){
Cat myCat = new Cat();
Cat theOtherCat = (Cat)myCat.clone();
}
}
可以调用默认的Clone()方法了。但下面的代码编译不能通过,请
帮忙看看,谢谢了。public class Cat implements Cloneable{
public static void main(String[] args){
Cat myCat = new Cat();
Cat theOtherCat = (Cat)myCat.clone();
}
}
public static void main(String[] args) throws CloneNotSupportedException
public class cloneableTest
{
public static void main(String [] args)
{
Cat myCat = new Cat("Meo");
Cat theOtherCat = myCat.clone();
theOtherCat.say();
}
private static class Cat implements Cloneable
{
public Cat(String s)
{
this.s = s;
}
public Cat clone()
{
Cat cloned = new Cat(this.s);
return cloned;
}
public void say()
{
System.out.println(this.s);
}
private String s;
}
}
Meo
368(6^_^)->
public Cat clone(){
return super.clone();
}
public static void main(String[] args){
Cat myCat = new Cat();
Cat theOtherCat = (Cat)myCat.clone();
}
}