Question

What is polymorphism in PYTHON object-oriented programming? Can I have a detailed and clear explanation please....

What is polymorphism in PYTHON object-oriented programming?

Can I have a detailed and clear explanation please. Thank you :)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Polymorphism

1 . Polymorphism means that a code will behave differently at different conditions .

2 . It means that same function name is present and have different signatures being used for different purposes .

3 . Different signatures include same function name with different return types , different no of arguments related to type , count of numbers of arguments .

1 . Example of Polymorphism

#Function 1

def helper ( int a , int b )

return a+b

#Function 2

def helper ( float a , float b )

return a*b

#Function 3

def helper ( int a , float b )

return a / b

#Function 4

def helper ( float a , int b )

return a - b

#DRIVER CODE

print ( helper ( 3 , 4 ) ) // FUNCTION 1 CALLED

print ( helper ( 3.9 , 5,2 ) ) // FUNCTION 2 CALLED

print ( helper ( 3, 6.8 ) ) // FUNCTION 3 CALLED

print ( helper ( 3.2 , 8 ) )   // FUNCTION 4 CALLED

2 . POLYMORPHISM WITH INHERITANCE

I . When child class have same name methods which is present in Parent class .

II . Here , we re - implement the methods in child class .

III . Occurs if A ( ) function is present in Parent Class , and Child classes overrides that A() function in it's body .

IV . Also called Method Overriding .  

EXAMPLE :

class parent :

def intro ( ) :

print ( " In parent class " )

def help1 ( a ) :

print ( " Inside a " )

class child ( parent ) :

def intro ( ) :

print ( " In child class " )

#DRIVER CODE

obj1 = parent ( )  

obj2 = child ( )

obj1.intro ( ) // OUTPUT : " In parent class " .  

obj2. intro ( ) // OUTPUT : " In child class " .  

Add a comment
Know the answer?
Add Answer to:
What is polymorphism in PYTHON object-oriented programming? Can I have a detailed and clear explanation please....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT