Explain the concept of polymorphism in OOP with an example.

  • Polymorphism allows objects of a subclass to be treated as objects of their superclass.
  • Polymorphism allows objects of a superclass to be treated as objects of their subclasses.
  • Polymorphism allows objects of different classes to be treated as objects of a common superclass.
  • Polymorphism allows objects of different classes to have methods with the same name but different functionality.
Polymorphism is a fundamental concept in OOP that allows objects to be treated as instances of their parent class, even when they are instances of their child classes. This facilitates code reusability and flexibility. An example of polymorphism is method overloading or overriding, where different classes may have methods with the same name but different implementations.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *