Inheritance

9
C++ C++ Inheritance Inheritance BY- Ashish Awasthi

Transcript of Inheritance

Page 1: Inheritance

C++C++InheritanceInheritance

BY- Ashish Awasthi

Page 2: Inheritance

IntroductionIntroduction►The capability of one class to inherit The capability of one class to inherit

properties from another class is called properties from another class is called INHERITANCE. INHERITANCE. This is the property of This is the property of OBJECT ORIENTED PROGRAMMING, OBJECT ORIENTED PROGRAMMING, which derives new classes (called which derives new classes (called derived classes) from old ones. With derived classes) from old ones. With the derived class inheriting the the derived class inheriting the properties, including the method of properties, including the method of the old class is known as base class. the old class is known as base class.

Page 3: Inheritance

Concept of INHERITANCE Concept of INHERITANCE

Base class

Property A

Property BProperty C

Derived From

Derived class

Property DProperty AProperty B Property C

Defined in Derived Class

Defined in Base Class But accessible from Derived Class

Page 4: Inheritance

Levels of INHERITANCELevels of INHERITANCE►(A)- Single Inheritance.(A)- Single Inheritance.►(B)- Multilevel Inheritance.(B)- Multilevel Inheritance.►(C)- Multiple Inheritance.(C)- Multiple Inheritance.►(D)- Hierarchical Inheritance.(D)- Hierarchical Inheritance.►(E)- Hybrid Inheritance.(E)- Hybrid Inheritance.

Page 5: Inheritance

Single InheritanceSingle Inheritance• In this INHERITANCE have only one Base class and one Derived class.

BASE CLASS

DERIVED CLASS

Page 6: Inheritance

Multilevel InheritanceMultilevel Inheritance• In this INHERITANCE we have a chain of all classes and one BASE LINE , In this we must have to use three classes, there is one Base class and more than one Derived classes.

BASE CLASS

DERIVED CLASSES

Class A

Class B

Class C

Page 7: Inheritance

Multiple InheritanceMultiple Inheritance•In this INHERITANCE we have more than one independent Base classes and one Derived class, connected with all Base classes.

BASE CLASSES

DERIVED CLASS

Class A Class B

Class C

Page 8: Inheritance

Hierarchical InheritanceHierarchical Inheritance•This INHERITANCE is just opposite of Multiple inheritance.

Class A

Class B Class C

BASE CLASS

DERIVED CLASES

Page 9: Inheritance

Hybrid InheritanceHybrid Inheritance•This is a combine form of Multiple and Hierarchical Inheritance.

Class B Class C

Class D

Class A

Derived Base class

BASE CLASS

DERIVED CLASS