My class:
public class Test {
Test(){
System.out.println("Hello World");
}
public void doSomething() {
System.out.println("Do something");
}
Test t = new Test(); //why its is ok, although it gives run time stack overflow exception
public static void main(String[] args) {
Test t = new Test();
t.doSomething();
}
}
its is giving exception, can anybody tell me why? because there is not compilation error when we create object outside main method, but when we running the program its gives error, why?