Saturday, 31 August 2013

Stack Overflow java

Stack Overflow java

Object as a class variable causes the stackoverflow
public class stack {
stack obj = new stack(); // its obvious that during class
loading obj will call class to
// load and infinite loop will occur.
}
Lets say i am using static in from class obj
public class stack {
static stack obj = new stack(); // it will not cause infinite loop
and program will //execute successfully
}
Static variables are allocated in to the memory when the class is caught
by JVM first time (As far I know). Say during first time only if the JVM
starts allocating the memory to the above static object variable. It will
intern call the class again and this should also cause infinite loop .
Somewhere i am wrong. Can somebody highlight where i am wrong.

No comments:

Post a Comment