zoukankan      html  css  js  c++  java
  • 特性:

    封装

    继承

    #   继承
    
    class People:
    
        def __init__(self, name, age):
            self.name = name
            self.age = age
    
        def eat(self):
            print("%s is eating..."%self.name)
    
        def sleep(self):
            print("%s is sleeping...."%self.name)
    
    
    class Man(People):      #  继承People
        def __init__(self, name, age, money):
            People.__init__(self, name, age)    #  调用父类的属性
            self.money = money    #  新增属性
            print("%s 一出生就有%s money"%(self.name, self.money))
    
        def piao(self):
            print("%s is piaoing...."%self.name)
    
        def sleep(self):    # 给父类添加新方法
            People.sleep(self)  # 直接调用父类方法
            print("man is sleeping.....")
    
    
    class Woman(People):    # 继承父类
        def get_birth(self):
            print("%s is born a baby...."%self.name)
        
        
    
    m1 = Man("HanChun", 22, 2)  # 有2块钱
    m1.eat()
    m1.piao()
    m1.sleep()
    
    w1 = Woman("ChenRong", 26)
    w1.get_birth()

    多态

  • 相关阅读:
    synchronized的原理
    ThreadLocal是什么?使用场景有哪些?
    什么是死锁?死锁产生的原因?
    15-错误
    14-异常处理
    13-接口
    12-方法
    11-结构体
    10-指针
    09-字符串
  • 原文地址:https://www.cnblogs.com/xieyi-newlife/p/9058142.html
Copyright © 2011-2022 走看看