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.
The probability of selecting a rotten apple randomly from a heap of 250 apples is 0.20. What is the number of rotten apples in the heap?
...Two dice are rolled together. Find the probability that the sum of the numbers on the two dice is less than 4.
A box contains only three colors of balls- red, green and blue. What is the minimum number of balls that should be picked from the box to ensure that at...
There are 4 red balls, 5 blue balls and 3 green balls in a jar. 2 balls are drawn at random. Find the probability that both balls are either green or red.
One five letter word is to be formed taking all letters – U, Z, M, O and Q. What is the probability that this formed word will contain all vowels tog...
A box contains only three colors of balls- red, green, and blue. What is the minimum number of balls that should be picked from the box to ensure that a...
Find the simplified value of the given expression:
18 × 3 ÷ 6 + 24 ÷ 4 of 2 − 60 ÷ 2 of 3 + 18 × 5 ÷ 9.Â
...In a lottery, there are 11 prizes and 30 blanks. A lottery is drawn at random. What is the probability of getting a prize?
From a bag containing 12 white and 15 yellow ribbons, find the probability of picking 2 ribbons of each type at random.
Five squares of a chessboard are chosen at random, the probability that three are of one colour and two of another is