Car class inheritance
发布时间
阅读量:
阅读量
学习类的继承
作者:雷蕾
编写一个新类作为现有现成class的子class时,则可以采用继承的方式
原有的old那个old old class被称为parent base类别(parent class或base class),而new创建的那个subclass则被称为subclass从属类别;该subclass不仅能够继承parent的所有attribute与method,并且还可以自定义新增一些新的attribute与method
我们可以defining 定义一个具体实例 subclass ElectricCar,并使其inherit 继承自 parent base Car的所有attribute与method:
class Car:
'''一次模拟汽车的简单尝试'''
def __init__(self,make,model,year):
self.make=make
self.model=model
self.year=year
self.odometer_reading=0
def
全部评论 (0)
还没有任何评论哟~
