eSoftTools IMAP Backup Software and migration tools
Oopc (group 9)
1. Shree Swami Atmanand Saraswati
Institute Of Technology
Presentation Topic:- Concept Of Inheritance
Prepared By :-
Kachariya Parth S. (150760107026)
Katharotiya Pratik K. (150760107028)
Kidecha Rahul M. (150760107031)
Parmar Jay V. (150760107042)
Guided By :-
Prof. Vrutti D. Shah
2. Content
1. Concept Of Inheritance
2. Types Of Inheritance
i. Single Inheritance
ii. Multiple Inheritance
iii. Multi-Level Inheritance
3. What Is Inheritance ?
• Inheritance is a feature in Object Oriented
Programming.
• It can be described as a process of creating new
classes from existing classes.
• New classes inherit some of the properties and
behaviour of the existing classes.
• An existing class that is "parent" of a new class is
called a base class. New class that inherits
properties of the base class is called a derived
class.
• Inheritance is a technique of code reuse.
• It also provides possibility to extend existing
classes by creating derived classes.
4. • To Inherit a single base class the syntax is as follows :
Syntax :- class new_classname : visibility_mode base_classname
• To Inherit more than one base class the syntax is as follows :
Syntax :- class new_classname : visibility_mode base_class_1_name ,
visibility_mode base_class_2_name ,
visibility_mode base_class_n_name
5. • It can be defined as which mode we want to inherit the base class.
• It consist of three modes
– Protected
– Private
– Public
Visibility Mode
Base Class Derived Class
Visibility
Public
Derivation
Private
Derivation
Protected
Derivation
Private Not inherited Not inherited Not inherited
Protected Protected Private Protected
Public Public Private Protected
6. Types Of Inheritance
• Now, the concept of inheriting and creating the derived class can be done by
several techniques.
7. • If a Class is derived from a single class then it is Single Inheritance.
• Class B is Derived From Class A as per the below example is called single
inheritance.
Single Inheritance
( Example Of Single Inheritance )
8. #include<iostream>
using namespace std;
class A
{
public:
void displayA()
{
cout<<“Display Class A”<<endl;
}
};
class B : public A //Class B Is Derived from Class A
{
public:
void displayB()
{
cout<<“Display Class B”<<endl;
}
};
Example
int main()
{
B b;
b.displayA();
b.displayB();
return 0;
}
OUTPUT :
Display Class A
Display Class B
9. • If a Class is derived from a class which is derived from another class then it is
Multi-Level Inheritance.
• Class C is Derived From Class B and Class B is derived from Class A as per the
below example is called Multi-Level inheritance.
Multi-Level Inheritance
( Example Of Multi-Level Inheritance )
10. #include<iostream>
using namespace std;
class A
{
public:
void displayA()
{
cout<<“Display Class A”<<endl;
}
};
class B : public A //Class B is derived
{ from Class A
public:
void displayB()
{
cout<<“Display Class B”<<endl;
}
};
Example
class C: public B //Class C Is Derived
{ from Class B
public:
void displayC()
{
cout<<“Display Class C”<<endl;
}
};
11. OUTPUT :
Display Class A
Display Class B
Display Class C
Display Class A
Display Class B
int main()
{
C c;
c.displayA();
c.displayB();
c,displayC();
B b;
b.displayA();
b.displayB();
b.displayC(); // Object of Class B can not call The return
0; function of Class C
}
12. • If a Class is derived from more than one class then it is a Multiple Inheritance.
• Class C is Derived From Class A and Class B as per the below example is called Multiple
Inheritance.
Multiple Inheritance
( Example Of Multiple Inheritance )
13. #include<iostream>
using namespace std;
class A
{
public:
void displayA()
{
cout<<“Display Class A”<<endl;
}
};
class B
{
public:
void displayB()
{
cout<<“Display Class B”<<endl;
}
};
Example
class C: public A, public B //Class C Is Derived
{ from Class A
public: and Class B
void displayC()
{
cout<<“Display Class C”<<endl;
}
};
int main()
{
C c;
c.displayA();
c.displayB();
c,displayC();
return 0;
}
OUTPUT :
Display Class A
Display Class B
Display Class C
15. class C : public A, public B //Class C Is Derived from Class A and Class B
{
int c;
public:
void mult()
{
c=get_a()*get_b();
cout<<c<<endl;
}
};
main()
{
C p;
p.getdata();
p.getdata1();
p.mult();
}
OUTPUT :
2
5
10