zoukankan      html  css  js  c++  java
  • 子类重用父类的功能

    # class Foo:
    # def f1(self):
    # print('Foo.f1')
    # def f2(self):
    # print('Foo.f2')
    # self.f1()
    #
    # class Bar(Foo):
    # def f1(self):
    # print('Bar.f1')
    #
    # obj=Bar()
    # obj.f2()
    # '''
    # Foo.f2
    # Bar.f1
    # '''
    # class OldboyPeople:
    # school = 'oldboy'
    # def __init__(self,name,age,gender):
    # self.Name=name
    # self.Age = age
    # self.Gender=gender
    # def tell_info(self):
    # print('<名字:<%s> 年龄:<%s> 性别:<%s>' %(self.Name,self.Age,self.Gender))
    #
    # class OldStudent(OldboyPeople):
    # def learn(self):
    # print('%s is learning'%self.name)
    # def tell_info(self):
    # print('我是学生:',end='')
    # # self.tell_info()
    # OldboyPeople.tell_info(self)
    #
    # stu1=OldStudent('婉婷',18,'female')
    # # teach1=OldTeacher('egon',28,'male')
    # stu1.tell_info()
    '''
    我是学生:<名字:<婉婷> 年龄:<18> 性别:<female>
    '''
    # class OldboyPeople:
    # school = 'oldboy'
    # def __init__(self,name,age,gender):
    # self.name=name
    # self.age=age
    # self.gender=gender
    # def tell_info(self):
    # print('<名字:<%s> 年龄:<%s> 性别:<%s>' %(self.name,self.age,self.gender))
    #
    # class OldStudent(OldboyPeople):
    # def __init__(self,name,age,gender,course,stu_id):
    # self.name=name
    # self.age=age
    # self.gender=gender
    # self.course=course
    # self.stu_id=stu_id
    # def learn(self):
    # print('%s is learning'%self.name)
    # def tell_info(self):
    # print('我是学生:',end='')
    # OldboyPeople.tell_info(self)
    #
    # stu1=OldStudent('婉婷',18,'female','python',1)
    # stu1.tell_info()
    '''
    我是学生:<名字:<婉婷> 年龄:<18> 性别:<female>
    '''
    # class OldboyPeople:
    # school = 'oldboy'
    # def __init__(self,name,age,gender):
    # self.name=name
    # self.age=age
    # self.gender=gender
    # def tell_info(self):
    # print('<名字:<%s> 年龄:<%s> 性别:<%s>' %(self.name,self.age,self.gender))
    #
    # class OldStudent(OldboyPeople):
    # def __init__(self,name,age,gender,course,stu_id):
    # OldboyPeople.__init__(self,name,age,gender)
    # self.course=course
    # self.stu_id=stu_id
    # def learn(self):
    # print('%s is learning'%self.name)
    # def tell_info(self):
    # print('我是学生:',end='')
    # OldboyPeople.tell_info(self)
    #
    # stu1=OldStudent('婉婷',18,'female','python',1)
    # stu1.tell_info()
    '''
    我是学生:<名字:<婉婷> 年龄:<18> 性别:<female>
    '''
  • 相关阅读:
    021.day21 反射 Class类 反射常用操作
    020.day20 线程概述 多线程优缺点 线程的创建 线程常用方法 生命周期 多线程同步
    019.day19 缓冲流 对象流 标准输入输出流
    018.day18 map集合如何实现排序 File类 IO流 字节流 字符流 编码
    017.day17 Map接口 克隆 treeSet集合排重缺陷
    016.day16 HashSet TreeSet 比较器Comparable Comparator
    015.day15
    014.day14
    013.day13
    线程
  • 原文地址:https://www.cnblogs.com/0B0S/p/12078072.html
Copyright © 2011-2022 走看看