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.
A certain sum of money becomes 5 times of itself in 20 years at simple interest. In how many years does it become double of itself at the same rate of s...
An amount becomes 2.5 times itself in 15 years at a simple interest rate of r% per annum. Find r.
A man invested a certain amount of sum at 12.5% per annum simple interest and earned an interest of Rs.2400 after 4 years. If the same amount is investe...
An individual 'P' received Rs. 6,750 as interest by investing Rs. 15,000 at a simple interest rate of 18% per annum for 'x' month...
- A man borrowed Rs. 5,300 at an annual compound interest rate of 12%, compounded yearly. He repaid the loan in two equal yearly installments. What was the a...
On a principal of Rs. 2000, simple interest at R% per annum for 3 years is Rs. 480. Find the simple interest on Rs. 2500 at (R + 4)% per annum for 5 years.
An amount doubles itself on simple interest in 3 years. What is the percent per annum rate of interest?
A certain sum of money invested at R% p.a. fetches a compound interest (compounded annually) of 1525.5 and simple interest of Rs.1500 at the end of 2 ye...
Difference between CI and SI on a sum for 3 year at 20% p.a. is 176. Find the simple interest on the sum after 2 years at 10% p.a.
Rs. 6,000 is deposited in Scheme 'X' which provides compound interest at 8% per annum, compounded annually. Another amount of Rs. 5600 is invested in Sc...