Java polymorphism creating a subclass object using its superclass variable

前端 未结 3 1843
猫巷女王i
猫巷女王i 2021-01-02 09:48

So I am a student and in the process of learning Java. There is one concept that I am having a difficult time grasping and am hoping that someone could shed some light on t

3条回答
  •  一生所求
    2021-01-02 10:03

    1. Any overridden methods in the Lizard class will be used instead of those in the Animal class

      Yes, you're right

    2. which classes constructor will be used while creating a?

      When you create a subclass, it will implicitly call super class's constructor. Hence, both super class, which is Animal, and sub class, which is Lizard, will be used.

提交回复
热议问题