Polymorphism vs Inheritance

后端 未结 6 1440
青春惊慌失措
青春惊慌失措 2021-02-01 20:23

Suppose I have two classes: Animal and Dog. Dog is a subclass of Animal. I do the following code:

Animal a = new Dog();

Now I can call methods

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-01 20:59

    inheritance is the dynamic polymorphism. I mean when you remove inheritance you can not override anymore.

提交回复
热议问题