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.
Loading...
Related Quiz
- Which encryption protocol is considered more secure for protecting wireless network traffic: WEP or WPA2?
- In a text processing application, you're tasked with finding all occurrences of a given word within a large document. How would you approach this problem using arrays and strings efficiently?
- What factors should be considered when choosing columns for indexing in a database table?
- The ___________ time is the maximum amount of time a process can execute before being interrupted in preemptive scheduling.
- In a file system, the ___________ keeps track of free and allocated disk blocks.