For example:
public class A {
public class B extends A {
}
public static void main(String[] args) {
A a;
a = new B();
}
}
I searched some similar questions and they showed "yes, a superclass type variable can refer to a subclass object". But in eclipse the above code comes up with an error like "No enclosing instance of type A is accessible. Must qualify the allocation with an enclosing instance of type A (e.g. x.new A() where x is an instance of A)."
So what wrong? Thanks!