You call: InstanceTest it = new InstanceTest(); -> constructor called InstanceTest it1 = new InstanceTest(); -> constructor called ... Recursion. Too deeply means that ideally this recursion is infinite
5-year Student of <br />Moscow Institute of Physics and Technology.
Stack overflow happens as you are calling the constructor (new InstanceTest()) within the constructor body - and this makes it a recursive function.
The function calls are stored on the stack of the process (jvm's process' stack memory). When a function is called, its return address and local vars/references are kept on the top of the stack. If this function calls another function (or itself - as in recursion) then the stack size grows to accomodate the new function's info. When there is no exit criteria specified for a recursion (as in your case) the functions keep adding to the top of the stack and there comes a time when stack size reaches the maximum possible size and the JVM process balks out complaining an overflow.