Single inheritance

kshMS 2,483 views 9 slides Aug 08, 2015
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

This presentation includes Inheritance in C++ with the 5 categories of Inheritance. Main part of the presentation is the 1st type of Inheritance i.e SINGLE LEVEL INHERITANCE including the Block Diagram,Example Code & Simple Program with Corresponding output. This slide was created & edited ...


Slide Content

Inheritance

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

S ingle L evel I nheritance

In s ingle l evel i nheritance, there is only one base class and has only one derived class . A B 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 S ingle L evel I nheritance. # include< iostream > # include< cstdlib > u sing 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