Python中的面向对象编程详解(下)
继承
继承描述了基类的属性如何“遗传”给派生类。一个子类可以继承它的基类的任何属性,不管是数据属性还是方法。
创建子类的语法看起来与普通(新式)类没有区别,一个类名,后跟一个或多个需要从其中派生的父类:
classSubClassName(ParentClass1[,ParentClass2,...]): 'optionalclassdocumentationstring' class_suite
实例
classParent(object):#defineparentclass定义父类 defparentMethod(self): print'callingparentmethod'
classChild(Parent):#definechildclass定义子类 defchildMethod(self): print'callingchildmethod'
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短