public class cation {
public static void main(String[] args) {
new cation().run();
}
public void run(){
harada hara=new harada();
insert(hara);
insert(hara);
}
public void insert(harada hara){
if(hara.left==null){
hara.left=new harada();
}
else{
insert(hara.left);
}
}
class harada{
harada left;
public harada(){}
}
}
Can someone please explain, recursion in objects as seen in the above code. I don't understand when i pass "hara.left in else condition", it passes it as if it were a new reference and therefore treats it null and makes a new instance of 'hara.left'. The problem is tht the if condition had already been called and the instance of 'hara.left' was already made!!
Thanks.