0% found this document useful (0 votes)
0 views

Python 3

The document outlines an academic assignment for students at Mahatma Gandhi Mission’s College of Engineering and Technology, focusing on Object Oriented Programming in Python. It includes three programming tasks: understanding classes and static methods, constructors, and inheritance with polymorphism. Each task is accompanied by source code examples demonstrating the concepts.

Uploaded by

shubham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Python 3

The document outlines an academic assignment for students at Mahatma Gandhi Mission’s College of Engineering and Technology, focusing on Object Oriented Programming in Python. It includes three programming tasks: understanding classes and static methods, constructors, and inheritance with polymorphism. Each task is accompanied by source code examples demonstrating the concepts.

Uploaded by

shubham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Mahatma Gandhi Mission’s College of Engineering and Technology

Department of Computer Science and Engineering (AIML & DS)

Academic Year 2024-2025(Even Sem)

Name Of Student Mohit Joshi

Roll No 20
DOP DOS Marks/Grade Signature

Experment No:-3

Aim: Write python programs to understand concepts of Object Oriented


Programming.

Objective:∙ Object Oriented Programming concepts in python.

Outcome: Students will be able to understand concepts of Object


Oriented Programming in python.

i) WAP to understand Classes, objects, Static method and inner class.

Source Code:

class OuterClass:
@staticmethod
def static_method():
return "This is a static method in the OuterClass."

class InnerClass:
def __init__(self, name):
self.name = name
def display(self):
return f"Hello from InnerClass, {self.name}!"

outer_object = OuterClass()
print(outer_object.static_method())

inner_object = OuterClass.InnerClass("PYTHON")
print(inner_object.display())

Input and Output:

ii) WAP to understand Constructors.

Source Code:

class Person:
def __init__(self, name, age):
self.name = name
self.age = age

def display_info(self):
return f"Name: {self.name}, Age: {self.age}"

person1 = Person("David", 30)


person2 = Person("Jhon", 25)
person3 = Person("Tom", 15)
print(person1.display_info())
print(person2.display_info())
print(person3.display_info())

Input and Output:

iii) WAP to understand Inheritance and Polymorphism with Method


overloading and Method Overriding.
Source Code:
class Animal:
def sound(self):
return "Some sound"

class Dog(Animal):
def sound(self):
return "Bark"

class Cat(Animal):
def sound(self):
return "Meow"

class Bird(Animal):
def sound(self):
return "Chirp"

class Calculator:
def add(self, a, b):
return a + b

def add_three(self, a, b, c):


return a + b + c

def demonstrate_inheritance_and_polymorphism():
animals = [Dog(), Cat(), Bird()]
for animal in animals:
print(f"{animal.__class__.__name__} makes sound:
{animal.sound()}")

def demonstrate_method_overloading():
calc = Calculator()
print("Addition of two numbers:", calc.add(10, 40))
print("Addition of three numbers:", calc.add_three(10, 20, 50))
demonstrate_inheritance_and_polymorphism()
demonstrate_method_overloading()
Input and Output:

You might also like