Advertisements
Advertisements
Question
Explain the following concept related to the object oriented programming:
Inheritance
Explain
Advertisements
Solution
Inheritance is a fundamental concept in OOP that allows a new class to acquire the properties and behaviors (data and methods) of an existing class. It promotes code reusability and helps in building organized and scalable programs.
- A child class (subclass/derived class) is created from an existing class.
- The parent class (superclass/base class) provides its members (variables and functions) to the child class.
- The child class can use, extend, or modify the inherited features.
Example:
class Animal {
public:
void eat() {
cout << "Eating..." << endl;
}
};
class Dog : public Animal {
public:
void bark() {
cout << "Barking..." << endl;
}
};shaalaa.com
Is there an error in this question or solution?
2024-2025 (July) Official Board Paper
