Ravaan Techky

Ravaan Techky Group invites all Techkies.

Python

Inheritance

Inheritance in Python:

  • Base class declaration
    #Base Class Animal
    class Animal():
        #constructor
        def __init__(self):
            print('Animal Created')
    
        #Method - Who Am I ?
        def whoamI(self):
            print('I am animal')
    
        #Method - Eat method
        def eat(self):
            print('Animal is Eating')
    
  • Base class object creation
      myAnimal = Animal()
    

Output=>

  Animal Created
  • Child class declaration
    #Child Class Dog
    class Dog(Animal):
      #constructor
      def __init__(self):
          Animal.__init__(self)
          print('Dog Created')
    
  • Child class object creation
    myDog = Dog()
    

    Output=>

    Animal Created
    Dog Created
    



Back


python-documentation is maintained by ravaan-techky.