Why Stack overflow error occurs on creating nonstatic instance within an instance of same class ??
public class ObjectTest {
ObjectTest instanceObj = new ObjectTest("Outside");
public ObjectTest(String s) {
System.out.println(s);
}
public static void main(String[] args) {
ObjectTest localObj = new ObjectTest("Inside");
}
}
But the problem gets resolved by below modification :
static ObjectTest instanceObj = new ObjectTest("Outside");
It is understood like circular dependency occurs in first case while assigning new object to instanceObj reference
Can anyone clarify the whole thing ?? Why for static reference circular dependency doesnot occur??