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.
Sentences are given below with a blank. Fill in these blanks with the appropriate option.
The friendly neighbor's __________ gesture of offer...
Located 140 km away from Srinagar, Drass valley in Kargil District is often described as the “Gateway to Ladakh.”
- In the question given below, there is a sentence of which some parts have been jumbled. Rearrange these parts, which are labeled as P, Q, R, and S, to prod...
The government is planning a capital __________ for the PSBs.
(A) involvement (B)inclusion (C) infusion (D) development
...- Fill in the blanks:
A true leader ________ confidence and earns the ________ of the team. Which conjunction can be used for this sentence?
He had a lot of problems in his family, __________ he managed to get the first place in the ...
Without a _____________ set of policies to persuade the electorate, the Republicans have resorted to sloganeering and empty rhetoric.
I.We are hopeful that the heavy rains predicted for next week will ______ the drought.
II.Calcium supplements can positively ______ one’s ...
His appointment caused disquiet __________ members.
The booking was made and the taxi was _______ a few minutes.