while i am running this code i got a run time exception saying Exception in thread "main" java.lang.StackOverflowError
Could some body help me out?
public class MyClass {
MyClass a = new MyClass(); public static void main(String[] args) { // TODO Auto-generated method stub MyClass b = new MyClass(); System.out.println("Inside main witout error"); }
}
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35220
7
posted
0
Each instanceof MyClass that gets created in turn creates another instance of MyClass. That will up the stack fast, since there is no end to this object creation.