Linked Questions

Popular Questions

Why New keyword (Constructor) gives StackOverFlowError?

Asked by At

In the given below code, it looks like there should be HeapMemoryOverFlowError because we are creating object inside object, but it gives StackOverflowError.

public class JavaConcepts {
    JavaConcepts jc = new JavaConcepts();
    public static void main(String[] args) {
        new JavaConcepts();     
    }
}

Exception in thread "main" java.lang.StackOverflowError

at Java.JavaConcepts.<init>(JavaConcepts.java:5)
at Java.JavaConcepts.<init>(JavaConcepts.java:5)
at Java.JavaConcepts.<init>(JavaConcepts.java:5)
at Java.JavaConcepts.<init>(JavaConcepts.java:5)

Related Questions