Class Inheritance in Python




Inheritance
  • A process of getting properties from one Class to other Class.
  • Properties are nothing but variables and methods.
  • The class which give its properties is called Super / Base / Parent Class.
  • The class getting properties is called Sub / Derived / Child Class.
  • Advantage of Inheritance
    • Code re-usability
    • Code extensibility
  • Python supports 5 types of Inheritance
    • Single Inheritance
                        One class will give its properties to other class.



    • Multiple Inheritance
                        One Class is derived from minimum 2 Base classes.
                        There is no link between two Base classes.

    • Multi-Level Inheritance
                        One class is derived from other derived class.

    • Hierarchical Inheritance
                        Minimum 2 classes are derived from One Base  class
                        Derived classes are not linked to each other

    • Hybrid Inheritance
                        It is a combination of 2 or more type of inheritance.





  • Remember, in Python everything is Inherited, means everything from a class to other class is inherited
  • There is no Concept of private or public or protected.

  • Overriding
            In overriding, inheritance always required as it is done between parent class(super class) and child class(child class) methods.

  • Overloading
            Overloading is nothing, but rewriting the two functions with same same name and different parameters. 
My photo
Techno Xpresss
Bangalore, Karnataka, India