Question
What is the purpose of Inheritance in Object-Oriented
Programming?                           ÂSolution
Inheritance is a key feature of Object-Oriented Programming (OOP) that allows a class (called the derived or child class) to inherit properties and methods from another class (called the base or parent class). This helps in reusing code and establishing hierarchical relationships between classes. The derived class can access and modify the behaviors of the base class, and it can also add its own additional methods and properties.
- Why It Is Important: Inheritance promotes code reuse , reduces redundancy, and enhances maintainability. It also enables the creation of a hierarchical relationship between classes, where a base class defines general behaviors, and derived classes specialize or extend those behaviors. This leads to a more organized and structured codebase.
- Real-World Example: Consider a class Vehicle with methods like start() and stop() . A subclass Car can inherit these methods from Vehicle and add its own methods, such as playMusic() , without having to re-implement the start() and stop() methods.
- Â To allow one object to create another object: This describes object creation or composition , not inheritance.
- To enable the hiding of internal details of an object: This refers to encapsulation , not inheritance.
- To allow the association between two independent objects: This refers to association or aggregation , not inheritance.
- To enable communication between objects of different types: This is an example of polymorphism or message passing , not inheritance.
Which of the following constitutions is popularly known as the peace constitution?
In 1770, who among the following performed a series of experiments that revealed the essential role of air in the growth of green plants?
With reference to CAG (Comptroller and Auditor General of India), consider the following statements:
1.CAG is a statutory body mentioned in the A...
What is the scientific field that studies skin diseases called?Â
Bandhan Bank's 'Avni' savings account is specifically designed for which group?
Union Home Minister Amit Shah launched the ‘Vibrant Villages Programme’ (VVP) in April 2023 in which district of Arunachal Pradesh?
Which bank has executed its first non-deliverable forex derivative transaction with Reliance Industries, after the Reserve Bank of India allowed such tr...
According to a recent report by the Food and Agriculture Organization (FAO) in August 2024, which food items were identified as containing microplastics?
In the Global Air Quality Index of SWISS FIRM IQAir for the year 2022, at what rank did India stand in terms of air quality worldwide?
The third edition of the Khelo India University Games 2023 started in which of the following states?