Python 36 Question Inheritance Polymorphism One Advantage Using Subclasses Ability Use Pol Q37020851

Python 3.6 Question:

Inheritance – Polymorphism

One advantage of using subclasses is the ability to usepolymorphism.

The idea behind polymorphism is that several different types ofobjects can have the same methods, and be treated in the sameway.

For example, have a look at the code we’ve included for thisproblem. We’ve defined Shape as an abstract base class. It doesn’tprovide any functionality by itself, but it does supply aninterface (in the form of .area() and .vertices()methods) which aremeaningful for any type of 2D Shape.

The total_area function makes use of this to calculate the areaof any kind of Shape. We’ve provided an example of this with

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.