Question
Which of the following best represents the concept of
polymorphism in Object-Oriented Programming?ÂSolution
Polymorphism in Object-Oriented Programming (OOP) allows methods to be defined in different forms across different derived classes, typically by overriding or overloading methods. This enables a single method to exhibit multiple behaviors, depending on the object that invokes it. For example, a base class method draw() in a shape class could be defined differently in derived classes like Circle and Rectangle, where each class implements its unique version of draw(). This approach promotes flexibility, reduces code duplication, and allows developers to manage code easily as new classes are added, embodying one of OOP’s core principles. Polymorphism is critical for creating extensible and maintainable code, as it enables a system to process objects of various types through a common interface. Option A (Encapsulation) - Encapsulation is the OOP principle of hiding internal details and exposing only necessary features through a class interface, which differs from polymorphism’s focus on varied behaviors. Option C (Aggregation) - Aggregation describes a "has-a" relationship between classes, where one class contains references to another, unrelated to polymorphic behavior. Option D (Encapsulation) - This concept of grouping related fields and methods within a class refers to encapsulation, not polymorphism. Option E (Unrelated Classes) - Allowing objects of unrelated classes to connect without a common functionality does not represent polymorphism, which requires shared interfaces or inheritance.
They also lay claim to being the only brothers to finish first and second in the same race.
- The following sentence has been divided into parts. One of them contains an error. Select the part that contains an error from the given options. If the se...
From on of the windows of my flat I can see the Qutub minar,” said my friend.
Plastics represent an example of (A)/a consumption externality, which involves much people, (B)/rather than a production externality, (C)/which involve...
In the question below, a sentence is given, divided into five parts (A) , (B) , (C) , (D) and (E) . One of the parts is grammatically incorrect or has ...
You should avoid (A)/to look into these matters as (B)/they are complicated and could be (C)/handled only by a professional (D).
Read the given sentence to find out whether there are any grammatical/ contextual errors in them. The errors, if any, will be in two of the parts of th...
In the question given below, a sentence is given, divided into parts. One of the parts may contain an error. Identify the part that contains the error,...
Read the following sentence carefully and identify if there is any grammatical error in it. If you find any error, choose the part (A, B, C, or D) con...
Guru Gobind Singh said it was our duty to come to the defence of all those who were threatened through no fault of their own.