7_22 day25 16min 继承
class Dad:
'这个是爸爸类'
money=10
def __init__(self,name):
print('爸爸')
self.name=name
def hit_son(self):
print('%s 正在打儿子' %self.name)
class Son(Dad):
def __init__(self,name,age):
self.name=name
self.age=age
def hit_son(self):
print('来自儿子类')
# print(Son.money)
10
#Son.hit_son(1)
来自儿子类,不穿参数报错
s1=Son('alex',18)
# s1.hit_son()
# print(s1.money)
# print(Dad.money)
# print(s1.name)
# print(s1.money)
# print(s1.__dict__)
alex
10
{'name': 'alex', 'age': 18}
s1.hit_son()来自儿子类
lass Dad:
'这个是爸爸类'
money=10
def __init__(self,name):
print('爸爸')
self.name=name
def hit_son(self):
print('%s 正在打儿子' %self.name)
class Son(Dad):
money = 1000000000009
def __init__(self,name,age):
self.name=name
self.age=age
def hit_son(self):
print('来自儿子类')
s1=Son('alex',18)
print(s1.money)
print(Dad.money)
1000000000009
10