abstrak:#_*_coding:utf-8 _*_
#父類
class Father:
def __init__(self):
self.Fname = 'fffffff'
#_*_coding:utf-8 _*_
#父類
class Father:
def __init__(self):
self.Fname = 'fffffff'
def Func(self):
print 'funcfurnc'
def Bar(self):
print 'barbarbar'
def Test(self): #再定義一個(gè)方法
print '11111'
print 'testtest'
#子類繼承父類,也就是說Son類可以拿到Father類的方法
class Son(Father):
def __init__(self):
self.Sname = 'sonsonson'
def Yes(self):
print 'barbarbar'
def Test(self):
print 'aaaaaaaa' #重寫父類的Test方法
#實(shí)例化子類,嘗試訪問在父類的方法
s1 = Son() #實(shí)例化子類
s1.Bar() #成功訪問父類的方法
s1.Test() #訪問重寫后的方法
f1 = Father()
f1.Test()
#_*_coding:utf-8 _*_
#多重繼承
class A(object):
def __init__(self):
print 'this is A'
def save(self):
print 'save method from A'
class B(A):
def __init__(self):
print 'this is B'
class C(A):
def __init__(self):
print 'this is C'
def save(self):
print 'save method from D'
class D(C,B):
def __init__(self):
print 'this is D'
c = D()
c.save()