When a Derived Class to inherit properties and behavior from a single Base Class , it is called as single inheritance.
Syntax of Single Inheritance:
Base_class : access_specifier derived_class
{
//body of subclass
};
Example:
#include<iostream>
using namespace std;
class Parent{ // parent class
protected:
int a;
int b;
public:
Parent(){
a = 10;
b = 20;
}
};
class Child: public Parent{ // child class
public:
void show(){
cout<< " Value of a= "<<a <<endl;
cout<< " Value of b= "<<b <<endl;
}
};
int main()
{
Child obj;
obj.show();
}
Output:
Value of a=10
Value of b=20
0 Comments
Thanks for Supporting me