Advertisements
Advertisements
प्रश्न
Explain the following concept related to the object oriented programming:
Inheritance
स्पष्ट करा
Advertisements
उत्तर
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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2024-2025 (July) Official Board Paper
