This is my code :
public class ConstructorsDemo{
public static void main(String a[]){
Cons1 c1 = new Cons1();
}
}
class Cons1{
Cons1 c = new Cons1();// the error is in this line
Cons1(){
//does somwthing
}
}
So I get an infinite loop error here (Stackoverflow). However it's fine if I comment out any of the two objects I have created.
How is the object c
in my code causing Stackoverflow error?