Home Tutorials Python OOP Concepts Complete Mini Example
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

🏋️ Test Yourself With Exercises

Take our quiz on Complete Mini Example to test your knowledge.

Browse Quizzes »