I ended up doing something that made me curious:
I created a following Cao class:
public class Cao {
String nomeDoCao = null;
Cao caes = new Cao();
public void setName(String name) {
nomeDoCao = name;
}
public String getName() {
return nomeDoCao;
}
}
public class Main {
public static void main(String[] args) {
Cao umCao = new Cao();
umCao.setName("Mike");
umCao.caes.setName("Rex");
umCao.caes.caes.setName("Totoh");
umCao.caes.caes.caes.caes.caes.setName("Bilu");
System.out.println(umCao.getName());
System.out.println(umCao.caes.getName());
System.out.println(umCao.caes.caes.caes.caes.caes.getName());
}
}
I get this error:
Exception in thread "main" java.lang.StackOverflowError
Does this become something infinite right? When programming there is the possibility of instantiating an object in the object itself? Or should NEVER do that?