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.
Choose the figure which is different from the rest.
What is the difference between the floor numbers of X and Y?
In each problem, out of the four figures marked (1) (2) (3) and (4), three are similar in a certain manner. However, one figure is not like the other t...
How many 5's are there followed by 3 but not preceded by 7?
7 5 3 1 6 8 5 8 4 3 5 3 7 1 6 1 5 8 6 4 5 3 2 5
...Which two signs should be interchanged to make the given equation correct?
125 × 5 + 2 ÷ 37 – 35 = 64
Choose the figure which is different from the rest.
Select the one which is different from the other three responses.
In each problem, out of the four figures marked (1) (2) (3) and (4), three are similar in a certain manner. However, one figure is not like the other t...
In each of the following questions select the one which is different from the other three responses.