Because at compile-time it doesn't reference anything. Here's an example:
How would the compiler know whether the marked assignment is valid? If i is 0 then it is, otherwise it isn't.Code:class Base {} class A extends Base {} class B extends Base {} class C extends Base {} public class Core { public static void main(String[] args) { int i = (int)(Math.random()*3.0); Base b; switch(i) { case 0: b = new A(); break; case 1: b = new B(); break; case 2: b = new C(); break; } A a = b; // !!! } }




CornedBee
Reply With Quote