What is the real significance(use) of polymorphism

前端 未结 10 2298
别跟我提以往
别跟我提以往 2020-12-01 01:44

I am new to OOP. Though I understand what polymorphism is, but I can\'t get the real use of it. I can have functions with different name. Why should I try to implement polym

10条回答
  •  有刺的猬
    2020-12-01 02:04

    I guess sometimes objects are dynamically called. You are not sure whether the object would be a triangle, square etc in a classic shape poly. example.

    So, to leave all such things behind, we just call the function of derived class and assume the one of the dynamic class will be called.

    You wouldn't care if its a sqaure, triangle or rectangle. You just care about the area. Hence the getArea method will be called depending upon the dynamic object passed.

提交回复
热议问题