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.
Determine the smallest four-digit number that is evenly divisible by 12, 22, and 42.
Three natural numbers X,Y,Z are pairwise co-prime and satisfy the following conditions, the least common multiple (LCM) of X and ...
The smallest natural number that must be added to 1212 to make it a perfect square is:
There are three numbers 'u', 'v' and 'w' (u < v < w) such that 'v' is equal to the average of 'u' and 'w'. 80% of 'w' is equal to 'u' and the difference...
If 893x2 is divisible by 56, and x > 6, find x.
Consider three numbers whose total is 294. The first and second numbers are in a ratio of 5:7, and the second and third numbers are in a ratio of 7:9. D...
- If 246x179y is divisible by 72, find the value of (x + 2y).
Find the sum of the first 30 natural numbers.
A number is initially increased by 37.5% and then reduced by 40%. The final value obtained after these changes is 6,270. Determine 80% of the original n...