大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#Author Kang
class Person(object): #父类
countPerson = 0 #公有属性
def __init__(self,name,sex): #类的初始化
self.Name = name
self.Sex = sex
Person.countPerson += 1 #统计注册人数,必须要这样写,否则无法形成统计
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.......!!!!!")
b2 = BlackPerson("kang","F","chiness")
b1 = BlackPerson("Jack","F","English")
b1.talking()
b1.walking()
print("当前人数:",Person.countPerson)
结果:
Jack is talking,Lanaguage is English
我是重构了父类的方法,walking.......!!!!!
当前人数: 2