Question
Which of the following is the primary reason why
polymorphism is useful in Object-Oriented Programming (OOP)?Solution
Polymorphism in OOP is primarily beneficial because it allows objects of different classes to be treated as objects of a common superclass. This enables objects to be used interchangeably, which is useful when designing flexible and reusable code. In OOP, polymorphism is achieved through method overriding (in inheritance) or interfaces, allowing for the same method name to behave differently depending on the object type invoking it. This leads to more generic code, easier maintenance, and greater extensibility. For instance, a superclass Shape could define a method draw() . Subclasses like Circle and Square would each override the draw() method, but polymorphism allows a reference of type Shape to invoke the draw() method of either subclass without needing to know which specific subclass it is dealing with. Why Other Options Are Incorrect:
- A) While encapsulation is a core OOP principle, it is not the primary reason polymorphism is useful. Encapsulation is concerned with hiding object details and is not directly related to the dynamic behavior of polymorphism.
- B) Inheritance is indeed a key OOP feature, but it is not polymorphism. Inheritance enables classes to inherit behavior, while polymorphism allows objects of different types to be treated uniformly.
- D) Constructors are used for object creation, and polymorphism is about dynamic method invocation, not constructor elimination.
- E) Object comparison (using methods like equals() ) is a different concept related to object equality rather than polymorphism.
Sale of a security that is not owned by the seller is called? Â
Which of the following is true about the Debit Card of the Banks?
I. By Automated Teller Machine customers can deposit or withdraw money from the...
What is the limit on the amount of money for trade related transactions under RDA?
Which of the following is the most volatile foreign capital?
The IMF and the World Bank were conceived as institutions to-
The share of net demand and time liabilities that banks must maintain in safe and liquid assets, such as, government  securities, cash and gold with...
In the context of Alternative Investment Funds, what does the term "locked-in period" refer to?
Who is the CEO of National Housing Bank?
The National Payments Corporation of India (NPCI) is an initiative taken by the _________________ to operate the retail payments and settlement systems ...
Forward Market Commission (FMC), which is now merged with SEBI, was mainly responsible to?