Inheritance concept in Object Oriented Programming.
Inheritance :
Inheritance is the process in Object Oriented Programming in which one class inherit the properties or attributes of another class.Inheritance is used to reduce the code in object oriented programming, we can easily acquires the attributes,functions of parent class to child class.
Inheritance is the important features of Object Oriented Programming because of code reusability.
Implementation symbol of inheritance is ' : ' .
Mode of Visibility in Inheritance:
1. Private : In private mode , the attribute and methods are only accessible within class.
Example:
Private:
int id,phone;
void display(){.......}
2. Protected : In protected mode , the attributes and method are accessible within class and the derived class.
Example:
Protected:
int id,phone;
void display(){.......}
3. Public : In public mode , the attribute and methods are accessible to all the class.
Example:
Public:
int id,phone;
void display(){.......}
Example of Inheritance:
#include <iostream>
using namespace std;
class Base{
public:
void display()
{
cout<<"This is Base class \n";
}
};
class Derived:public Base
{
public:
void show()
{
cout<<"This is Derived class \n";
}
};
int main()
{
Derived obj;
obj.display();
obj.show();
return 0;
}
Output:
Comments
Post a Comment