-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritence.cpp
More file actions
34 lines (26 loc) · 968 Bytes
/
Inheritence.cpp
File metadata and controls
34 lines (26 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Inheritance is a fundamental concept in Object-Oriented Programming (OOP) that allows a class to inherit properties and behaviors (methods) from another class. This promotes code reusability and establishes a relationship between classes.
// Types of Inheritance in C++
// Single Inheritance: A class inherits from one base class.
// Multiple Inheritance: A class inherits from more than one base class.
// Multilevel Inheritance: A class is derived from another derived class.
// Hierarchical Inheritance: Multiple classes inherit from a single base class.
#include <iostream>
using namespace std;
class Base {
public:
void display(){
cout << "Base class display function" << endl;
}
};
class Derived : public Base {
public:
void show() {
cout << "Derived class show function" << endl;
}
};
int main() {
Derived obj;
obj.display(); // Base class function
obj.show(); // Derived class function
return 0;
}