Jeevachaithanyan Sivanandan

Python - class and INHERITANCE

· 1 min read

Here a very minimal representation of Class Inheritance in Python

class Bird:
  def __init__(self,name):
    self.name=name

  def fly(self):
    print (self.name + " can fly")
    
    
sparrow = Bird('Robin')
sparrow.fly()

class Aeroplane(Bird):
  
  def __init__(self, model):
    self.model = model
    
  def fly(self):
    print (self.model + " can also fly like a bird")
  
  def takeoff(self):
    print (" but " +  self.model +  " is not a bird !")
    

boieng = Aeroplane('Boeing')
boieng.fly()
boieng.takeoff()