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.
In the Solow Model, what is the impact of an increase in the savings rate on the steady state level of capital per worker?
  Consider the following production function
Y = F(K,AL) = K1/3(AL)2/3
Calculate the Golden state level of capita...
India traditionally runs a large Merchandise Trade Deficit (Goods). What is the key component that typically counteracts this to keep the Current Accoun...
The Economic Survey 2023-24 highlights a decline in out-of-pocket expenditure on health as a percentage of total health expenditure from 64.2% in FY14 t...
Which of the following is true about Omission(Overfitted) and Inclusion(Underfitted) type of the specification error
If X(bar) = 25, Y(bar) = 120, bxy = 2. Find the value of X when Y=130?
Production function of two companies producing floppy and discs was given.
Q1 = 10L^0.5 K^0.5 Q2 = 10L^0.6K^0.4
Which of the following i...
Since the 1980s, Wal-Mart stores have appeared in almost every community in America. Wal-Mart buys its goods in large quantities and, therefore, at chea...