Explain the concept of polymorphism in OOP with an example.

  • It allows a class to inherit from multiple classes
  • It is the process of converting objects into different types
  • It is used for encapsulation in OOP
  • It refers to the ability of a class to provide different implementations for the same method
Polymorphism in OOP refers to the ability of a class to provide different implementations for the same method. For example, method overloading and method overriding are forms of polymorphism. Method overloading involves defining multiple methods with the same name but different parameters in the same class. Method overriding occurs when a derived class provides a specific implementation for a method already defined in its base class. This flexibility allows for more versatile and readable code.
Add your answer
Loading...

Leave a comment

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