__author__ = '12711'
#-*- coding:utf-8 -*-
# class Animal(object):
# name='xxx'
# def __init__(self,name,age):
# self.name=name
# self.age=age
#
# def eat(self):
# print("%s开始吃东西了"%(self.name))
#
# def seelp(self):
# print("%s开始睡觉了"%(self.name))
#
# t=Animal('小花',22)
# print(Animal.name)
# t.seelp()
# t.eat()
#类的封装
# class Animal(object):
# def __init__(self,name,age):
# self.__name=name
# self.age=age
#
# def __eat(self):
# print("%s开始吃东西了"%(self.__name))
#
# def seelp(self):
# print("%s开始睡觉了"%(self.__name))
# t=Animal('xiaohua',22)
# t.eat()
# t.seelp()
# class A:
# def fa(self):
# print('from A')
# def test(self):
# self.fa()
#
# class B(A):
# def fa(self):
# print('from B')
#
# b=B()
# b.test()
# class A:
# def __fa(self):
# print('from A')
# def test(self):
# self.__fa()
#
# class B(A):
# def __fa(self):
# print('from B')
#
# b=B()
# b.test()
#类的继承
# class Animal(object):
# def __init__(self,name,age):
# self.name=name
# self.age=age
#
# def Age(self):
# print("%s已经%d岁了"%(self.name,self.age))
#
# def eat(self):
# print("%s开始吃东西了"%(self.name))
#
# def seelp(self):
# print("%s开始睡觉了"%(self.name))
#
# class Dog(Animal):
# def __init__(self,name,age,color):
# super(Dog,self).__init__(name,age)
# self.color=color
#
# def voice(self):
# print("%s汪汪汪的叫起来。。"%(self.name))
#
#
# class Cat(Animal):
# def __init__(self,name ,age,color):
# super(Cat,self).__init__(name,age)
#
#
# def voice(self):
# print("%s喵喵喵的叫起来了。。"%(self.name))
#
#
#
# t1=Dog("小白",3,"白色")
# t2=Cat("小花",2,"黑白斑点")
# t1.seelp()
# t1.eat()
# t1.Age()
# t1.voice()
# t2.seelp()
# t2.eat()
# t2.Age()
# t2.voice()
#类的多继承
class Animal(object):
def __init__(self,name,age):
self.name=name
self.age=age
def Age(self):
print("%s已经%d岁了"%(self.name,self.age))
def eat(self):
print("%s开始吃东西了"%(self.name))
def seelp(self):
print("%s开始睡觉了"%(self.name))
class Love(object):
def frand(self,obj):
print("%s和%s变成了朋友"%(self.name,obj.name))
class Dog(Animal,Love):
def __init__(self,name,age,color):
super(Dog,self).__init__(name,age)
self.color=color
def voice(self):
print("%s汪汪汪的叫起来。。"%(self.name))
class Cat(Animal):
def __init__(self,name ,age,color):
super(Cat,self).__init__(name,age)
def voice(self):
print("%s喵喵喵的叫起来了。。"%(self.name))
t1=Dog("小白",3,"白色")
t2=Cat("小花",2,"黑白相间")
t1.frand(t2)
转载于:https://www.cnblogs.com/hjdshizhidong/p/9812931.html