- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Does Python support polymorphism?
Yes,Python support polymorphism.
The word polymorphism means having many forms.
polymorphism is an important feature of class definition in Python that is utilised when you have commonly named methods across classes or sub classes.
Polymorphism can be carried out through inheritance, with sub classes making use of base class methods or overriding them.
There are two types of polymorphism
Overloading: Overloading occurs when two or more methods in one class have the same method name but different parameters.
Overriding: Overriding means having two methods with the same method name and parameters (i.e., method signature). One of the methods is in the parent class and the other is in the child class.
class Fish(): def swim(self): print("The Fish is swimming.") def swim_backwards(self): print("The Fish can swim backwards, but can sink backwards.") def skeleton(self): print("The fish's skeleton is made of cartilage.") class Clownfish(): def swim(self): print("The clownfish is swimming.") def swim_backwards(self): print("The clownfish can swim backwards.") def skeleton(self): print("The clownfish's skeleton is made of bone.") a = Fish() a.skeleton() b = Clownfish() b.skeleton()
When we run the program with the python polymorphism.py command, we will get an expected output −
The fish's skeleton is made of cartilage. The clownfish's skeleton is made of bone.
- Does Python support multiple inheritance?
- Does MySQL support table inheritance?
- Does java support hybrid inheritance?
- Does Selenium support Safari browser?
- Polymorphism in Python
- Does HTML5 Canvas support Double Buffering?
- Does C++ support Variable Length Arrays
- Does Java support multi-dimensional Arrays?
- Does Selenium support headless browser testing?
- What type of comments does C++ support?
- Does cypress support api automation testing also?
- Python class browser support
- Does Java support default parameter values for a method?
- Difference between compile-time polymorphism and runtime polymorphism