python inheritance example parent class (python3 syntax)

#coding=utf8

class Cup:

  # Constructor initializes the property value
  DEF the __init __ (Self, Capacity, Color):
    self.capacity = Capacity
    self.color = Color

  retain_water DEF (Self):
    Print ( "Cup Color:" + self.color + ", the cup capacity:" + self.capacity + "., is filled with water")

  keep_warm DEF (Self):
    Print ( "Cup Color:" + self.color + ", the cup capacity:" + self.capacity + ", is incubated.")

class Luminous_Cup(Cup):

  # Constructor call the constructor initializes the parent class attribute value
  DEF the __init __ (Self, Capacity, Color):
    Super () .__ the init __ (Capacity, Color)

  Glow DEF (Self):
    Print ( "I am the light-emitting ...")


currentCup=Luminous_Cup('300ml','翠绿色')
currentCup.retain_water()
currentCup.glow()

Guess you like

Origin www.cnblogs.com/xiaoxiaoshuaishuai0219/p/11684700.html