@ Prabhakar : When the main()
thread starts its execution in its call stack inside the JVM, the following things happen (in order):
a) The statement
invokes the constructor of the class.
b) Remember this, whenever a constructor is invoked, all the instance variables of the class are assigned their respective values(either default or through setters and getters) for this new object on the heap.
c) As a part of action in statement (b) above, since this instance variable assignment
at line 3 is itself a part of the class's instance variables, it will again invoke the constructor of the class.
d) This second invocation of the constructor again tries to do the action mentioned in (c ) above. This is where the memory gets screwed up. This action will never complete since the instance variable assignment is calling the same constructor which initiated that assignment. And so the stack overflows its capacity.
Let me know in case you have any further doubts.