Polymorphism is a fundamental concept in object-oriented programming (OOP) that allows objects of different classes to respond to the same message (method call or function call) in different ways. The word itself means "many forms". In the context of the question, it refers to how data or a message can be handled or processed.
Let's examine each option to see which one best defines polymorphism:
This description is incorrect. While polymorphism deals with messages, processing them all in strictly "one way" contradicts the core idea of "many forms". This sounds more like a single, specific operation.
This is the opposite of what polymorphism means. If a message can only be processed in one form, it lacks flexibility and the "many forms" aspect is missing.
This is the correct definition. Polymorphism allows the same message or data to be interpreted and acted upon in multiple different ways, depending on the context or the object receiving it. For example, a 'speak()' message might result in a 'bark' from a Dog object and a 'meow' from a Cat object.
This option is vague and incorrect. Polymorphism applies to defined messages and data types, not "undefined" ones. While it requires processing in at least one way, the key is the possibility of *multiple* ways.
Based on the analysis, polymorphism fundamentally means that a single interface (like a message or function name) can be used to represent different underlying forms or implementations. Option 3 accurately captures this essence.
Which operator is used for dynamic memory allocation in C++?
Which statements is correct regarding main () function in C++?
I. It is a user defined function.
II. It is a pre-defined function.
Consider the following segment of C++ code.
int j, n;
for(j=1;j<=n; )
j=j*2;
What is the number of comparisons made in the execution of the loop for any n > 0?