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

Interview Question (25!11!2024)

Uploaded by

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

Interview Question (25!11!2024)

Uploaded by

POOJA DHAKANE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Interview Question-[25-11-2024]

Q.1 What is Polymorphism?


Ans:
Polymorphism is a fundamental concept in object-oriented programming (OOP) that
allows a single interface or function to represent different types of objects or
behaviors.

Q.2 How to achieve Polymorphism?


Ans:
Polymorphism can be achieved in two main ways:
A. Method Overloading
B. Method Overriding

Q.3 What is Overloading explain with example.


Ans:
Overloading in Python refers to defining multiple methods or functions with the
same name but different parameter lists or behavior. While Python does not support
traditional method overloading like some languages like Java.

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

calc = Calculator()
print(calc.add(5)) # 5
print(calc.add(5, 3)) # 8
print(calc.add(5, 3, 2)) # 10

Q.4 What is Overriding. Explain with example.


Ans:
Overriding is an object-oriented programming feature where a child (or derived)
class provides a specific implementation for a method that is already defined in
its parent (or base) class. The overridden method in the child class replaces the
method in the parent class when called through an instance of the child class.
#Example:
class Animal:
def sound(self):
return "Animals make sounds"

class Dog(Animal):
def sound(self):
return "Dogs bark"

class Cat(Animal):
def sound(self):
return "Cats meow"

dog = Dog()
cat = Cat()

print(dog.sound()) #Dogs bark


print(cat.sound()) #Cats meow

You might also like