A DESCRIPTION OF THE PROBLEM :
static StaticTestOne so1 = new StaticTestOne(); // reference variable marked as static
StaticTestOne so2 = new StaticTestOne(); // reference variable marked as a non static field
The above two lines of code were entered outside main method and in class scope and the main method was left blank. When the program was executed, it threw Java Exception from JVM and futher displayed a stack overflow error. But the program successfully executes when only one of the two statements are given. The statement with static invokes the constructor and the statement without static shows no output. But the combination of these two throws error in the form of Java Exception.
---------- BEGIN SOURCE ----------
package com.statictest;
public class StaticTestOne {
static StaticTestOne so1 = new StaticTestOne();
StaticTestOne so2 = new StaticTestOne();
public static void main(String[] args) {
}
}
---------- END SOURCE ----------
FREQUENCY : always
static StaticTestOne so1 = new StaticTestOne(); // reference variable marked as static
StaticTestOne so2 = new StaticTestOne(); // reference variable marked as a non static field
The above two lines of code were entered outside main method and in class scope and the main method was left blank. When the program was executed, it threw Java Exception from JVM and futher displayed a stack overflow error. But the program successfully executes when only one of the two statements are given. The statement with static invokes the constructor and the statement without static shows no output. But the combination of these two throws error in the form of Java Exception.
---------- BEGIN SOURCE ----------
package com.statictest;
public class StaticTestOne {
static StaticTestOne so1 = new StaticTestOne();
StaticTestOne so2 = new StaticTestOne();
public static void main(String[] args) {
}
}
---------- END SOURCE ----------
FREQUENCY : always