What did I do wrong here? Need to print -1 and 100 but I keep getting this error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing instance of type Main (e.g. x.new A() where x is an instance of Main). at Main.main(Main.java:3)
public static void main(String[] args) {
MyClass a = new MyClass();
MyClass b = new MyClass(100);
System.out.println(a.getValue()); // -1
System.out.println(b.getValue()); // 100
}
public class MyClass {
private int value;
// Constructors
public MyClass() {
value = -1;
}
public MyClass(int x) {
value = x;
}
public int getValue() {
return value;
}
}
}