#-*-coding:utf-8-*-
__author__ = "logan.xu"
#多继承
#class People: 经典类
class People(object): #新式类的多继承的方式有变化
def __init__(self,name,age):
self.name = name
self.age = age
self.friends = []
def eat(self):
print("%s is eating....." %self.name)
def talk(self):
print("%s is talking..." %self.name)
def sleep(self):
print("%s is sleeping..." %self.name)
class Relationship(object):
def make_friend(self,obj): #w1
self.friends.append(obj) #friends 如果改名就很麻烦
print("%s is making friends with %s"%(self.name,obj.name))
class Man(People,Relationship):
#子类继承父类people
#在子类中重构方法,先从子类中访问。值先传到子类man中,在到父类找
#在子类中添加woman子类没有的参数money
#然后在继承父类的参数,并定义子类man的money参数
def __init__(self,name,age,money):
# People.__init__(self,name,age)
#多个参数使用可以这样写
super(Man,self).__init__(name,age)
#新式类的多继承的方式有变化
#super的作用与People.__init__(self,name,age)作用是一样的
#super继承父类的构造函数,😋就是不用多次修改people名字来重构父类
self.money = money
print("%s出生带金钥匙%smoney"%(self.name,self.money))
def piao(self):
print("%s is piaoing....20s...done"%self.name)
#重构父类的方法
def sleep(self):
People.sleep(self) #调用父类的方法把self传进去
print("man is sleeping")
#添加子类woman
class Woman(People,Relationship):
def get_birth(self):
print("%s is born a baby..."%self.name)
def cook(self):
print("%s cooking many food,i love it ..."%self.name)
def shopping(self):
print("%s My wife so pretty,dress on beautiful clothes."
"it's just white fu mei's long legs"%self.name)
#两个子类之间不能相互调用类的方法
#m1实例化
m1 = Man("Jordan",22,1000000)
#m1.eat()
#m1.piao()
#m1.sleep()
#w1实例化
w1 = Woman("Lydia",20)
#w1.get_birth()
#w1.cook()
#w1.shopping()
m1.make_friend(w1)
print(m1.friends[0])