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.
An agreement made without free consent is:
Under Minimum Wages Act, the……………… may add to either Part of the Schedule any employment in respect of which minimum wages should be fixed a...
In which of the following case the supreme court has declared S. 303 of IPC as unconstitutional?
Under Employees Provident Fund & Miscellaneous Provision Act 1952 t he contribution which shall be paid by the employer to the Fund shall be ………�...
Which of the following is a necessary condition in case computer output can be treated as an electronic record as per s.65 B of Indian Evidence Act, 1872?
Partner's liability for acts of the firm is___?
Dunlop Pneumatic Tyre Co. Ltd. V. Selfridge & Co. provides for _______________
What does Competent Authority under the RTI Act, 2005 mean?
When no provision is made as to the duration of partnership in any contract it is_____.
What is the time limit to get the information under RTI Act 2005?