#_ *_coding:utf-8 _*_# Parent class class father: def __init__ (self): self. fname = ' fffffff ' def func (self): print ' FUNCFURNC ' def bar (self): print ' Barbarbar ' def test (self): #再定义一个方法 print ' 11111 ' print ' Testtest ' #子类继承父类, that is to say Son class can get Father class method Class son (Father): def __init__ (self): self. sname = ' Sonsonson ' def yes (self): print ' Barbarbar ' def test (self): print ' aaaaaaAA ' #重写父类的Test方法 # instantiates subclasses, tries to access Methods S1 = son () #实例化子类s1 in the parent class. Bar () #成功访问父类的方法s1. Test () #访问重写后的方法f1 = father () F1. Test ()
#_ *_coding:utf-8 _*_# Multiple Inheritance Class A (object): Def __init__ (self): print ' The ' 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): p Rint ' This was C ' def Save (self): print ' Save method from D ' Class D (c,b): def __init__ (self): print ' th IS is d ' C = d () c.save ()
This article is from the "Fa&it-Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1874313
Python's Simple chat class inheritance