I am writing a simple code and I am receiving an StackOverflowError in following code at line 2: Tmp4 t = new Tmp4 ();
I dont get error if I omit line 6 ( initialization of p
) or on omiting line 2. Also I am not doing a recursive call.
I want to ask why it is giving a such Error. And on omitting line 2 or line 6 it is not giving StackOverflowError.
Also it gives on my system only or problem with the code.
Thanks.
public class Tmp4 {
Tmp4 t = new Tmp4 ();
public static void main(String[] args) {
System.out.println("main");
Tmp4 p = new Tmp4 ();
System.out.println("main2");
}
}