public class TestClone implements Cloneable{
int count;
TestClone next;
public TestClone(int count){
this.count=count;
if(count>0) //递归 一连串的 next 对象??
next=new TestClone(count-1);
}
void add(){
count++;
if(next!=null) //怎么循环??弄不懂他的联系机制,如c/c++里有指针,那么这里??
next.count++; //就是说他怎么传递下去的
}
public String toString(){ //为什么制动调用这个方法????
String s=String.valueOf(count)+"";
if(next!=null) //这里也一样???
s+=next.toString();
return s;
}
public Object clone(){
Object o=null;
try{
o=super.clone();
}catch(Exception e)
{System.out.println("cannot clone");}
return o;
}
public static void main(String []args){
TestClone c=new TestClone(5);
System.out.println("c="+c);//输出为5 4 3 2 1 0 怎么能过输出对象C??
TestClone cl=(TestClone)c.clone();
System.out.println("c="+c);//输出为5 4 3 2 1 0
c.add();
System.out.println("after added\nc="+c+"\ncl="+"cl");//输出为6 5 3 2 1 0 四到那里去了??
} // 5 4 3 2 1 0
}
int count;
TestClone next;
public TestClone(int count){
this.count=count;
if(count>0) //递归 一连串的 next 对象??
next=new TestClone(count-1);
}
void add(){
count++;
if(next!=null) //怎么循环??弄不懂他的联系机制,如c/c++里有指针,那么这里??
next.count++; //就是说他怎么传递下去的
}
public String toString(){ //为什么制动调用这个方法????
String s=String.valueOf(count)+"";
if(next!=null) //这里也一样???
s+=next.toString();
return s;
}
public Object clone(){
Object o=null;
try{
o=super.clone();
}catch(Exception e)
{System.out.println("cannot clone");}
return o;
}
public static void main(String []args){
TestClone c=new TestClone(5);
System.out.println("c="+c);//输出为5 4 3 2 1 0 怎么能过输出对象C??
TestClone cl=(TestClone)c.clone();
System.out.println("c="+c);//输出为5 4 3 2 1 0
c.add();
System.out.println("after added\nc="+c+"\ncl="+"cl");//输出为6 5 3 2 1 0 四到那里去了??
} // 5 4 3 2 1 0
}
public String toString(){ //为什么制动调用这个方法????
String s=String.valueOf(count)+"";
if(next!=null)
s+=next.toString();
return s;
}
但是 main 函数里面并没有调用这个方法呀????另外什么是: tij appendex A ??