It is the capability of one class to Inherit the properties from another
class which is already exist in the program. The class from which
another class is Derived is known as Base Class or Parent Class &
the class which is derived from the Base Class is known as Sub-
Class or Child Class.
Concept
2
Types of Inheritance’s :
Single Inheritance
Multiple Inheritance
Hierarchical Inheritance
Multi-Level Inheritance
Hybrid Inheritance 3
Single Level Inheritance
In single level inheritance, there is only one base
class and has only one derived class.
Base Class
Derived Class
Here “A” is the Base class & “B” is the Derived class of “A”, i.e. “B” has the similar
properties of that the class “A” consist. 5
Example :
class Base
{
};
class Derv: public Base
{
};
6
A sample program to ADD two values using Single Level Inheritance.
#include<iostream>
#include<cstdlib>
using namespace std;
class first //base or parent class
{
public: //Access Specifier
int a,b;
void getdata() //member function getdata()
{
cout<<"nEnter Number : t";
cin>>a>>b;
}
void putdata() //member function putdata()
{
cout<<"nNumbers are : t"<<a<<"t"<<b;
}
};
class second :public first //class second inherits
property of class first
{
public : //Access Specifier
int c;
void add()
{
getdata();
putdata();
c=a+b;
cout<<"nAfter Addition : t"<<c;
}
};
int main()
{
system(“clear”);
second s1; //s1 is object of class second
s1.add();
return 0;
}
7
Output
Enter Number : 10 20
Numbers are : 10 20
After Addition : 30
8
By,
Akshay Kumar M S
BCA’14

Single inheritance

  • 2.
    It is thecapability of one class to Inherit the properties from another class which is already exist in the program. The class from which another class is Derived is known as Base Class or Parent Class & the class which is derived from the Base Class is known as Sub- Class or Child Class. Concept 2
  • 3.
    Types of Inheritance’s: Single Inheritance Multiple Inheritance Hierarchical Inheritance Multi-Level Inheritance Hybrid Inheritance 3
  • 4.
  • 5.
    In single levelinheritance, there is only one base class and has only one derived class. Base Class Derived Class Here “A” is the Base class & “B” is the Derived class of “A”, i.e. “B” has the similar properties of that the class “A” consist. 5
  • 6.
    Example : class Base { }; classDerv: public Base { }; 6
  • 7.
    A sample programto ADD two values using Single Level Inheritance. #include<iostream> #include<cstdlib> using namespace std; class first //base or parent class { public: //Access Specifier int a,b; void getdata() //member function getdata() { cout<<"nEnter Number : t"; cin>>a>>b; } void putdata() //member function putdata() { cout<<"nNumbers are : t"<<a<<"t"<<b; } }; class second :public first //class second inherits property of class first { public : //Access Specifier int c; void add() { getdata(); putdata(); c=a+b; cout<<"nAfter Addition : t"<<c; } }; int main() { system(“clear”); second s1; //s1 is object of class second s1.add(); return 0; } 7
  • 8.
    Output Enter Number :10 20 Numbers are : 10 20 After Addition : 30 8
  • 9.