类的继承与多继承

3.6 继承

class Father(object):

“”“父类(基类)”""

def init(self,name):

self.name=name

print(self.name)

def cook1(self):

print(“阳春面”)

class Son(Father):

“”“子类(派生类)”""

def init(self):

self.name=input(“请输入姓名:”)

print(self.name)

def cook2(self):

print(“重庆小面”)

if name == ‘main’:

f=Father(“A”)

s=Son()

s.cook1()

子类可以使用父f=Father(“A”)

s=Son()

s.cook1()

子类在继承的时候,在定义类的时候,()填写的是父类的名字

父类的属性和方法,子类可以继承并使用

class Son(Father):

3.7 多继承

class Son(Father,a,b,c,):

查找顺序

Father–a--b–c--c(object)

猜你喜欢

转载自blog.csdn.net/qq_44090577/article/details/88800566