0% found this document useful (0 votes)
25 views7 pages

Week 10

The document outlines Experiment Number 10 conducted by Girish Pattnaik, focusing on inheritance, method overriding, and polymorphism in Python. It includes several problem statements that involve creating base and subclass relationships, implementing methods, and demonstrating the concepts through code examples. The conclusion emphasizes the practical applications and efficiency of object-oriented programming in Python.

Uploaded by

steveryan2200
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)
25 views7 pages

Week 10

The document outlines Experiment Number 10 conducted by Girish Pattnaik, focusing on inheritance, method overriding, and polymorphism in Python. It includes several problem statements that involve creating base and subclass relationships, implementing methods, and demonstrating the concepts through code examples. The conclusion emphasizes the practical applications and efficiency of object-oriented programming in Python.

Uploaded by

steveryan2200
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
You are on page 1/ 7

Experiment Number 10

Date of Experiment 21.03.25

Date of Submission 28.03.25

Name of student Girish Pattnaik

Roll Number 2330230

Section ECS Group-1

Title of the Experiment:


Demonstrating Inheritance, Method Overriding, and Polymorphism in Python

Aim of the Experiment:


To understand and implement inheritance, method overriding, and polymorphism by creating base
and subclass relationships in Python.

Programming Language used:


Python
Problem Statement -1
Define a base class Shape with attributes color and filled, and a method get_info() that prints the
color and whether the shape is filled or not. Create a subclass Rectangle that inherits from Shape
and adds attributes length and width. Implement a method calculate_area() in Rectangle to
compute the area of the rectangle.

Code

Output
Problem Statement -2
Create a base class Vehicle with attributes make, model, and year, and a method display_info() to
print these attributes. Create a subclass Car that inherits from Vehicle and adds an attribute
mileage. Implement a method display_info() in Car to include the mileage along with the other
attributes.

Code

Output
Problem Statement -3
Define a base class Animal with a method sound() that prints the sound the animal makes. Create
subclasses Dog and Cat that inherit from Animal and override the sound() method to print the
specific sound each animal makes.

Code

Output
Problem Statement -4
Create a base class Person with attributes name and age, and a method introduce() to print the
name and age of the person. Create a subclass Student that inherits from Person and adds an
attribute student_id. Implement a method introduce() in Student to include the student ID along
with the name and age.

Code

Output
Problem Statement -5
Define a base class BankAccount with attributes account_number, balance, and methods deposit()
and withdraw() to add or subtract funds from the account. Create a subclass SavingsAccount that
inherits from BankAccount and adds an attribute interest_rate. Implement a method add_interest()
in SavingsAccount to calculate and add interest to the account balance.

Code

Code
Conclusion
The experiment demonstrates inheritance and polymorphism by reusing and extending base class
attributes and methods. It showcases practical applications in real-world scenarios, highlighting
the flexibility and efficiency of object-oriented programming in Python.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy