封装,继承,多态
2019-08-06 本文已影响0人
_PatrickStar
# 封装 将方法封装在类下面
class Animal:
def run(self):
print("animal run")
def eat(self):
print("animal eat")
def talk(self):
print("animal talk")
# a = Animal()
# a.run()
# 继承 Person类继承了Animal类的三个方法
class Person(Animal): # 继承
def study(self):
print("person study")
#多态 同一个方法 在子类下面重写
def talk(self):
print("person talk")
class Dog(Animal):
def talk(self):
print("dog talk")
p = Person()
# print(p.eat())
p.talk()
d = Dog()
d.talk()