Inheritance_in_Cpp_OOP
Inheritance_in_Cpp_OOP
What is Inheritance?
Inheritance is a mechanism in C++ where a new class (derived) is created from an existing class (base). It
Syntax
class Base {
// base members
};
// derived members
};
Types of Inheritance
Access Specifiers
|-------------|----------------|-------------------|-----------------|
class Parent {
public:
void show() {
};
public:
void greet() {
};
Output
I am Parent
Benefits of Inheritance
- Code Reusability
- Logical structure
- Easier maintenance
- Enables polymorphism