Complete Mini Example
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
Complete Mini Example
40. Complete Mini Example
A small real-world OOP example often combines constructor use, instance variables, inheritance, method overriding, and encapsulation-style access in one program.
Example
class Person:
def __init__(self, name):
self.name = name
def show(self):
print("Name:", self.name)
class Teacher(Person):
def __init__(self, name, subject):
super().__init__(name)
self.subject = subject
def show(self):
print("Name:", self.name)
print("Subject:", self.subject)
obj = Teacher("Ramesh", "Python")
obj.show()
Output
Name: Ramesh
Subject: Python
Example
Executing...
❌ Error:
✅ Output:
// Click Run ▶ to execute
🏋️ Test Yourself With Exercises
Take our quiz on Complete Mini Example to test your knowledge.
Browse Quizzes »