Python 3
Python 3
Roll No 20
DOP DOS Marks/Grade Signature
Experment No:-3
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())
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}"
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 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: