官术网_书友最值得收藏!

Polymorphism with classes (abstract classes)

There may be occasions in which we would want to define a template of a class in terms of what that class must do, but not in terms of how it should do it – we would want to leave that to the implementation of the class. This is where we can make use of abstract classes. Let's create a script called Poly_class.py and add the following code:

It can be seen that we have an abstract class called Shape, which has an area method. The area method is not implemented in this class, but it would be implemented in the child class. The Square and Circle child classes override the area method. The area method is polymorphic, which means that if a square overrides it, it implements the area of a square and when a Circle class overrides it, it implements the area of a circle.

主站蜘蛛池模板: 万宁市| 五峰| 神木县| 晋中市| 斗六市| 安图县| 仁布县| 霍林郭勒市| 富民县| 扎赉特旗| 肇庆市| 资阳市| 布尔津县| 寻乌县| 邓州市| 建始县| 金溪县| 大余县| 威海市| 鄂伦春自治旗| 衡阳市| 阳新县| 大田县| 洛隆县| 施秉县| 平南县| 武隆县| 洪江市| 桐庐县| 土默特右旗| 南涧| 峨眉山市| 英山县| 乌拉特中旗| 拉萨市| 聊城市| 太保市| 灌云县| 通许县| 泸水县| 阿鲁科尔沁旗|