Explain single inheritance with suitable example.
When a single derived class is derived from only one base class then it is called as single inheritance.
In a single inheritance, derived class can inherit some or all members of base class. It is implemented by specifying base class name and visibility mode proceeded with colon symbol while declaring derived class as shown below.
class base
{
};
class derived: public base
{
};
Example:
#include<iostream.h>
#include<conio.h>
class College
{
protected:
int a;
};
class Student: public College
{
public:
void getdata()
{
cin>>a;
}
void putdata()
{
cout<<a;
}
};
void main()
{
Student s;
clrscr();
s.getdata();
s.putdata();
getch();
}