java.lang.ClassException: A cannot be cast into B

后端 未结 13 1177
南笙
南笙 2020-12-31 09:05

I implemented this code:

class A {
    //some code
}
class B extends A {
    // some code
}

class C {
    public static void main(String []args)
    {
              


        
13条回答
  •  粉色の甜心
    2020-12-31 09:22

    When B extends A, it means all methods and properties of A are also present in B.

    So you can ever cast B to A,

    but you CANNOT cast A to B.

    You have to be really care about casting in your application.

提交回复
热议问题