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.
If the shareholder has purchased a share when the market price is Rs.50 and sold after a year to Mr. B at 55 and he has received the dividend of Rs.10, ...
Which of the following bank-financed facilities is NOT classified as NPA even when other credit facilities of the same borrower are classified as NPA?
Any casual vacancy in the office of an auditor shall in the case of a company whose accounts are subject to audit by an auditor appointed by the Comptro...
What does CBLO stand for?
Which banking transaction involves the transfer of funds from one bank account to another electronically, often used for paying bills or making purchases?
Fixed cost per unit increases when:
Which of the following Indian Accounting Standard (Ind AS), deals with the reporting and disclosure of contingent liabilities and contingent assets? �...
S, an entity had 500 units of product X at 30 June 2015. The product had been purchased at a cost of $18 per unit and normally sells for $24 per unit. R...
An asset is purchased for Rs. 10,000, on which depreciation is to be provided annually according to the straight-line method. The life of the asset is 4...
A manufacturing company sells a product for ₹500 per unit. The variable cost per unit is ₹300, and the fixed costs are ₹12,00,000 annually. Manage...