What is polymorphism, what is it for, and how is it used?

前端 未结 28 2783
南笙
南笙 2020-11-21 07:08

What is polymorphism, what is it for, and how is it used?

28条回答
  •  被撕碎了的回忆
    2020-11-21 07:37

    Polymorphism is the ability to treat a class of object as if it is the parent class.

    For instance, suppose there is a class called Animal, and a class called Dog that inherits from Animal. Polymorphism is the ability to treat any Dog object as an Animal object like so:

    Dog* dog = new Dog;
    Animal* animal = dog;
    

提交回复
热议问题