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.
Who among the following is ranked 12th in the Bloomberg Billionaires Index with a wealth of $110 billion?
Which cross-incubation programme was launched to strengthen agricultural innovation between India and Brazil?
Which sanctuary hosted the 8th Uttarakhand Bird Festival in 2024?
Which logistics company  has joined ONDC (Open Network for Digital Commerce), enabling Pan India delivery services to over 20,000 pin codes?Â
...What was the total construction cost of the multi-disciplinary sports stadium built in Dibrugarh, Assam?
Edson Arantes do Nascimento , commonly known as Pele passed away at the age of 82, on 29th december, 2022, he was known for?
The Asian Development Bank (ADB) has approved $112 million loan for _________ to strengthen skill education and training through establishment of the st...
How is Dhanpat Rai Srivastava better known as?
Which of the following is India's first water metro project ?
Which team won the Men's Hockey 5s Asia Cup title?