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.
Ramesh sets the price of an item at 36% above its cost price. If he raises the discount offered from 12% to 18%, his profit decre...
A merchant sold a gadget incurring a 30% loss. If he had marked up the price by 20% and then given a 15% discount, he would have earned Rs. 120 more. Fi...
The difference between the cost price and sale price of an article is Rs.600 and the profit is 30%. Find the selling price.
A shopkeeper sold an article after giving a discount of 20% and made a profit of Rs. 65. Find the marked price of the article if cost price of the artic...
The marked price of the washing machine is 40% above its cost price. The seller offers two successive discounts of 25% and 15%, respectively. If he incu...
By selling an article for 2640, a person loses 15% of its selling price. At what price (in RS) should he sell it to gain 15% on its cost price?
The selling price of a washing machine is Rs. 1680. If the washing machine was sold at 40% profit, then find the discount offered given that the washing...
The ratio of cost price and selling price of a shirt is 6:7 respectively. The shirt was marked up by 20% above its cost price, and sold after giving Rs....
A person earn 18% profit on the marked price. If he quadruple the marked price but gave 40% discount on the new marked price then how much percentage of...
Arjun sells an article at profit of 8%. If he had bought it at 5% less and sold it for ₹120 more he would have made a profit of 20%. what will be the ...