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.
Loading...
Related Quiz
- Which stage of CI/CD involves automatically deploying changes to a production environment?
- In SQL, the SELECT statement is used to _______ data from a database.
- The "Application" tab in Browser Developer Tools is used for managing _______.
- In Docker, a _______ defines the environment in which a container runs, including base image, dependencies, and commands to run.
- _______ allows developers to automate repetitive tasks such as code formatting, testing, and deployment, improving productivity and consistency across projects.