派生
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Hoer:
def __init__(self,nickname,life_value,aggresivity):
self.nickname = nickname
self.life_value = life_value
self.aggresivity = aggresivity
def attack(self,enemy):
enemy.life_value -= self.aggresivity
class Garen(Hoer):
camp = 'Demacia'
def attack(self,enemy):
print('form Garen Class')
class Riven(Hoer):
camp = 'Noxus'
g1 = Garen('草丛伦',100,30)
r1 = Riven('小雯雯',80,50)
g1.attack(r1)
# 打印结果:
form Garen Class