Upcasting Downcasting

后端 未结 5 752
攒了一身酷
攒了一身酷 2020-12-21 17:41

I have a parent class class A and a child class class C extends A.

A a=new A();
C c=(C)a;

This gives me error. Wh

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 18:07

    A is not a subclass of C hence you cannot cast it down.

提交回复
热议问题