0% found this document useful (0 votes)
2 views6 pages

OOPs Lab Inheritance in Python

The document provides examples of inheritance in Python through various class structures, demonstrating how subclasses can inherit properties and methods from parent classes. It includes multiple examples such as Person, Student, Employee, Manager, Vehicle, and others, showcasing method overriding and multiple inheritance. Each example illustrates the instantiation of objects and the invocation of their methods, highlighting the functionality of inheritance in object-oriented programming.

Uploaded by

Kirti Sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

OOPs Lab Inheritance in Python

The document provides examples of inheritance in Python through various class structures, demonstrating how subclasses can inherit properties and methods from parent classes. It includes multiple examples such as Person, Student, Employee, Manager, Vehicle, and others, showcasing method overriding and multiple inheritance. Each example illustrates the instantiation of objects and the invocation of their methods, highlighting the functionality of inheritance in object-oriented programming.

Uploaded by

Kirti Sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OOPs lab Inheritance in Python

March 19, 2026

[1]: class Person:


def __init__(self, name, age):
[Link] = name
[Link] = age

def display(self):
print("Name:", [Link])
print("Age:", [Link])

class Student(Person):
def __init__(self, name, age, roll):
Person.__init__(self, name, age)
[Link] = roll

def show(self):
[Link]()
print("Roll No:", [Link])

s = Student("Kirti", 22, 101)


[Link]()

Name: Kirti
Age: 22
Roll No: 101

[2]: class Person:


def __init__(self, name):
[Link] = name

class Employee(Person):
def __init__(self, name, salary):
Person.__init__(self, name)
[Link] = salary

class Manager(Employee):
def __init__(self, name, salary, dept):
Employee.__init__(self, name, salary)
[Link] = dept

1
def display(self):
print([Link], [Link], [Link])

m = Manager("Aman", 50000, "HR")


[Link]()

Aman 50000 HR

[3]: class Vehicle:


def __init__(self, brand):
[Link] = brand

class Car(Vehicle):
def __init__(self, brand, speed):
Vehicle.__init__(self, brand)
[Link] = speed

class SportsCar(Car):
def __init__(self, brand, speed, top_speed):
Car.__init__(self, brand, speed)
self.top_speed = top_speed

def display(self):
print([Link], [Link], self.top_speed)

s = SportsCar("BMW", 200, 300)


[Link]()

BMW 200 300

[4]: class Father:


def show_father(self):
print("This is father")

class Mother:
def show_mother(self):
print("This is mother")

class Child(Father, Mother):


def show_child(self):
print("This is child")

c = Child()
c.show_father()
c.show_mother()
c.show_child()

This is father

2
This is mother
This is child

[5]: class Teacher:


def __init__(self, name):
[Link] = name

class Researcher:
def __init__(self, field):
[Link] = field

class Professor(Teacher, Researcher):


def __init__(self, name, field):
Teacher.__init__(self, name)
Researcher.__init__(self, field)

def display(self):
print([Link], [Link])

p = Professor("Dr. Rao", "AI")


[Link]()

Dr. Rao AI

[6]: class Shape:


def info(self):
print("This is a shape")

class Rectangle(Shape):
def __init__(self, l, b):
self.l = l
self.b = b

def area(self):
print("Rectangle Area:", self.l * self.b)

class Circle(Shape):
def __init__(self, r):
self.r = r

def area(self):
print("Circle Area:", 3.14 * self.r * self.r)

r = Rectangle(5, 3)
c = Circle(4)

[Link]()
[Link]()

3
[Link]()
[Link]()

This is a shape
Rectangle Area: 15
This is a shape
Circle Area: 50.24

[7]: class Account:


def __init__(self, balance):
[Link] = balance

class SavingsAccount(Account):
def show_savings(self):
print("Savings Balance:", [Link])

class CurrentAccount(Account):
def show_current(self):
print("Current Balance:", [Link])

s = SavingsAccount(1000)
c = CurrentAccount(2000)

s.show_savings()
c.show_current()

Savings Balance: 1000


Current Balance: 2000

[8]: class Person:


def __init__(self, name):
[Link] = name

class Employee(Person):
def __init__(self, name, salary):
Person.__init__(self, name)
[Link] = salary

class Student(Person):
def __init__(self, name, roll):
Person.__init__(self, name)
[Link] = roll

class Intern(Employee, Student):


def __init__(self, name, salary, roll):
Employee.__init__(self, name, salary)
Student.__init__(self, name, roll)

4
def display(self):
print([Link], [Link], [Link])

i = Intern("Riya", 15000, 101)


[Link]()

Riya 15000 101

[9]: class Device:


def __init__(self, brand):
[Link] = brand

class Mobile(Device):
def __init__(self, brand, model):
Device.__init__(self, brand)
[Link] = model

class Camera(Device):
def __init__(self, brand, mp):
Device.__init__(self, brand)
[Link] = mp

class Smartphone(Mobile, Camera):


def __init__(self, brand, model, mp):
Mobile.__init__(self, brand, model)
Camera.__init__(self, brand, mp)

def display(self):
print([Link], [Link], [Link])

s = Smartphone("Samsung", "S23", 108)


[Link]()

Samsung S23 108

[10]: class Animal:


def eat(self):
print("Animal eats")

class Mammal(Animal):
def walk(self):
print("Mammal walks")

class Dog(Mammal):
def bark(self):
print("Dog barks")

5
d = Dog()
[Link]()
[Link]()
[Link]()

Animal eats
Mammal walks
Dog barks

[ ]:

You might also like