We can use members of one class inside another class by using the following ways:-
Is-A Relationship | Has-A Relationship |
---|---|
If we want to extend existing functionality with some more extra functionality then we should go for IS-A Relationship | If we don’t want to extend and just we have to use existing functionality then we should go for HAS-A Relationship |
The concept of inheriting the properties from one class to another class is known as single inheritance.
The concept of inheriting the properties from multiple classes to single class with the concept of one after another is known as multilevel inheritance.
The concept of inheriting properties from one class into multiple classes which are present at same level is known as Hierarchical Inheritance.
The concept of inheriting the properties from multiple classes into a single class at a time, is known as multiple inheritance. If the same method is inherited from both parent classes, then Python will always consider the order of Parent classes in the declaration of the child class.
Combination of Single, Multi level, multiple and Hierarchical inheritance is known as Hybrid Inheritance.
super() is a built-in method which is useful to call the super class constructors, variables and methods from the child class.
Various Important Points about super():
Case-1: From child class we are not allowed to access parent class instance variables by using super(),Compulsory we should use self only. But we can access parent class static variables by using super().
Case-2: From child class constructor and instance method, we can access parent class instance method, static method and class method by using super()
Case-3: From child class, class method we cannot access parent class instance methods and constructors by using super() directly(but indirectly possible). But we can access parent class static and class methods.
Case-4: In child class static method we are not allowed to use super() generally (But in special way we can use)