类的继承代码
#Author Kang
class Person(object): #父类
def __init__(self,name,sex): #类的初始化
self.Name = name
self.Sex = sex
def walking(self): #类的方法
print("%s is walking"%self.Name)
class BlackPerson(Person): #子类
def __init__(self,name,sex,language): #初始化函数,先继续父类,再重构自己
Person.__init__(self,name,sex)
self.Language = language
def talking(self): #子类的方法
print("%s is talking,Lanaguage is %s"%(self.Name,self.Language))
def walking(self): #重构父类的方法或不写直接调用父类
print("我是重构了父类的方法,walking.......!!!!!")
b1 = BlackPerson("Jack","F","English")
b1.talking()
b1.walking()
结果:
Jack is talking,Lanaguage is English
我是重构了父类的方法,walking.......!!!!!
原文地址:http://blog.51cto.com/12965094/2352760
时间: 2024-10-27 19:19:44