About Question com.enthuware.ets.scjp.v6.2.457 :
Posted: Tue Nov 06, 2012 9:22 pm
Hello, the very first line in explanation says:
since class A is a superclass of class B, how come a=b is subclass to superclass cast, this one requires an explicit cast!
which refers to the code line 1 here:The line 1 will be allowed during compilation, since assignment is done from a subclass reference to a superclass reference.
Code: Select all
A[] a, a1;
B[] b;
a = new A[10]; a1 = a;
b = new B[20];
a = b; // 1
b = (B[]) a; // 2
b = (B[]) a1; // 3
}
}
class A { }
class B extends A { }