139. Using super() for Method Resolution
1. Basic Single Inheritance with super()
super()class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def speak(self):
super().speak() # Calling parent class method
print("Dog barks")
dog = Dog()
dog.speak()Output:
Animal speaks
Dog barks2. Multiple Inheritance with super()
super()Output:
3. Using super() with __init__() in Multiple Inheritance
super() with __init__() in Multiple InheritanceOutput:
4. super() in Diamond Problem (Multiple Inheritance)
super() in Diamond Problem (Multiple Inheritance)Output:
5. Calling a Parent Method from a Subclass in Multiple Inheritance
Output:
6. Avoiding Explicit Class Names with super()
super()Output:
7. Super with __del__() Method
__del__() MethodOutput:
8. Super in Method Overriding with Arguments
Output:
9. Calling super() with staticmethod
super() with staticmethodOutput:
10. Using super() in a Method with Arguments in Multiple Inheritance
super() in a Method with Arguments in Multiple InheritanceOutput:
Explanation:
Summary:
Last updated