Hi Liao,
Try this instead!
code:
class Base {}
class Sub extends Base {}
class A{
public static void main(String argv[]){
Base b=new Base();
//Sub s=(Sub) b;//Line :1 Here is the runtime exception!
Base c= new Sub();
Sub d = (Sub) c;
}
}
What happens is that in compile time the compiler only checks the references have compatibilty or not, as you have casted it properly in line : 1. But in runtime a subclass cannot caontain a superclass object. Here i m a little
whether i m right about in runtime what happens.
Someone expalin plz....
------------------
azaman