5
I ended up doing something that made me curious:
I created a Cao class to follow:
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 mistake:
Exception in thread "main" java.lang.StackOverflowError
Does this become something infinite correct? When programming there is the possibility of instantiating an object in the object itself? Or should NEVER do this?
This is the example of the error message that already gives the hint of where to find the answer... ;)
– utluiz