class test{
int a;
test(int i){
a=i;
}
test incrbyten(){
test temp=new test(a+10);
return temp;
}
}
class retob{
public static void main(String args[]){
test ob1=new test(2);
test ob2;
ob2=ob1.incrbyten();
System.out.println("ob1.a"+ob1.a);
System.out.println("ob2.a"+ob2.a);
ob2=ob2.incrbyten();
System.out.println("ob2.a after second increase: "+ob2.a);
}
}
我始终不明白class test中test incrbyten()是成员函数。但为什么incrbyten()前面还加test,这不是自调用吗?是递归吧。而且我没找到调处的条件。
对它的理解进入了死循环,怎么也想不出输出结果:
ob1.a :2
ob2.a :12
ob2.a after second increase: 22
但事实上,调试通过了