Single Inheritance

Estudies4you

1. Single Inheritance

It refers to the process of deriving a class from a single base class. It has only one base and one derived class as shown in figure,
define Inheritance,explain single Inheritance,types of Inheritance,what is Inheritance,estudies4you,syntax for single Inheritance,examples of single Inheritance,definition of single Inheritance,oops lecture notes,c++ lecture notes,c++ study material,varaka kiran kumar
Figure: Single Inheritance
Syntax
class baseclass
{
-----------
};
class Derived : Visibility base class
{
-----------
}

Example
class Automobile
{
//body
};
class Cars : public Automobiles
{
// body
};
Program
#include<iostream:h>
#include<conio.h>
class B
{
int a;
public:
int b;
void get_ab();
int get_a();
void show_a();
};
class D: private B
{
int c;
public:
void mul();
void display();
};
void B::get_ab()
{
cout<<“Enter Values for a and b”;
cin>>a>>b;
}
int B::get_a()
{
return a;
}
void B::show_a()
{
cout<<“a= "<<a<<“\n”;
}
void D::mul()
{
get_ab();
c=b* get_a();
}
void D:: display()
{
show_a();
cout<<“b= "<<b<<“\n”;
cout<<“c= "<<c<<“\n\n”;
}
void main()
{
clrscr();
D d;
d.mul();
d.display( );
d.mul();
d.display( );
getch();
}
Output
define Inheritance,explain single Inheritance,types of Inheritance,what is Inheritance,estudies4you,syntax for single Inheritance,examples of single Inheritance,definition of single Inheritance,oops lecture notes,c++ lecture notes,c++ study material,varaka kiran kumar

To Top