What is the difference between Abstraction and Polymorphism

后端 未结 11 659
别那么骄傲
别那么骄傲 2021-01-30 07:17

I seem to not understand two OOP concepts very well. Could you explain what abstraction and polymorphism are, preferably with real examples and

11条回答
  •  借酒劲吻你
    2021-01-30 07:51

    very easy.

    1. Abstraction is abstraction. Class 'Student' is an abstraction of a real student.

    2. Polymorphism is when one class represents another so that user won't notice. This could happen when classes implement the same interface or one class derives from another. Class 'HighSchoolStudent' is derived from class 'Student'. When class 'Teacher' calls #attendance method on the object it might not know whether this object is of 'Student' class or 'HighSchoolStudent' class.

提交回复
热议问题