Question
Which of the following is an example of Polymorphism in
Object-Oriented Programming?Solution
Polymorphism is one of the fundamental principles of Object-Oriented Programming (OOP) and refers to the ability of a function, method, or operator to act on different types of data. The word “polymorphism” literally means "many forms," and in OOP, it allows objects of different classes to be treated as objects of a common superclass. The most common types of polymorphism are method overriding and method overloading .
- Why It Is Important: Polymorphism enables flexibility and scalability in code. It allows a method to be used with different types of objects, which reduces code redundancy and promotes code reusability. For example, a single method in a base class could be used for different derived classes, as long as the derived classes implement the same method.
- Real-World Example: Consider an abstract class Animal with a method sound() . The subclasses Dog and Cat override the sound() method. When the method sound() is called, it produces different results based on the object type ( Dog or Cat ), demonstrating polymorphism.
- A base class object cannot access the methods of a derived class: This is a misunderstanding of inheritance. A base class object cannot access the methods specific to a derived class unless the object is of the derived type.
- A derived class can directly modify private attributes of the base class: This violates the principle of encapsulation . A derived class cannot directly access private members of the base class unless accessors are provided.
- Â An object can only interact with its own type: This contradicts polymorphism, as polymorphism allows objects to interact with different types through method overriding or overloading.
- Data members of a class are always public: This is incorrect. Data members can be public, private, or protected, but OOP encourages encapsulation, where data members are often private, not public.
A sum of money is invested at a rate of 12% per annum compound interest for 2 years. If the total amount after 2 years is ₹11,520, what is the princip...
A man borrowed ₹10,000 at an interest rate of 12% per annum compounded annually. He repaid ₹4,000 at the end of the first year. What amount should h...
A man invests ₹50,000 in a scheme offering compound interest at 10% per annum, compounded annually. He withdraws ₹25,000 after 2 years. If he lets t...
The compound interest received on investing Rs. 4000 for 2 years at a compound interest of 20% p. a compounded annually is how much percentage more than...
What will be the amount payable on Maturity of ₹2,250 invested for three years 20% p.a. interest compounded yearly?
What is the difference between the compound interest, when interest is compounded 5-monthly, and the simple interest on a sum of ₹12,000 for 1(1/4) y...
Divide Rs. 53,285 into two parts such that the amount received from first part after 12 years is equal to the amount received from second part after 8 y...
A sum of ₹10000 is invested at compound interest for 2 years. If the interest rate is 5% per annum, what is the total amount after 2 years?
Determine the compound interest earned on a principal amount of Rs. 10,000, which is invested at an annual interest rate of 42%, with interest being com...