Inheritance
Introduction to OOP's
Class
Object
Constructor
Instance Variables
Class Variables
Instance Methods
self Keyword
Encapsulation
Public Members
Protected Members
Private Members
Inheritance
Single Inheritance
Multiple Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Hybrid Inheritance
super() Function
Polymorphism
Method Overriding
Duck Typing
Abstraction
Abstract Class
Abstract Method
Class Method
Static Method
Special Methods
_str_ Method
Operator Overloading
Composition
Aggregation
Association
Method Resolution Order
Object Class
issubclass() and isinstance()
Property Decorator
Setter Method with @property
Destructor
Inner Class
Complete Mini Example
Inheritance
12. Inheritance
Inheritance allows a child class to reuse attributes and methods from a parent class. It improves code reuse and supports hierarchical relationships between classes.
Syntax
class Child(Parent):
pass
Example
class Animal:
def eat(self):
print("I can eat")
class Dog(Animal):
def bark(self):
print("I can bark")
obj = Dog()
obj.eat()
obj.bark()
Output
I can eat
I can bark
Example
Executing...
❌ Error:
✅ Output:
// Click Run ▶ to execute
🏋️ Test Yourself With Exercises
Take our quiz on Inheritance to test your knowledge.
Browse Quizzes »