inheritance. 2 the process of deriving new class from the existing one is called inheritance then...
TRANSCRIPT
![Page 1: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/1.jpg)
Inheritance
![Page 2: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/2.jpg)
2
InheritanceThe process of deriving new class from the
existing one is called inheritanceThen the old class is called base class and the new
class is called derived class or sub classThe derived class inherits some or all properties
of base classAdvantages
Reusability of the code to increase the reliability of the code
to add some enhancements to the base class
![Page 3: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/3.jpg)
3
InheritanceDefining derived classSyn:class derived class : visibility mode base class name{};: indicates the derived class is derived from the base
class nameVisibility mode optional by default private
visibility mode specifies the features of the base class are privately derived or publicly derived or protected derived
![Page 4: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/4.jpg)
4
InheritanceThe derivations are three types
1 public2 private3 protected
![Page 5: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/5.jpg)
5
InheritancePublic inheritanceIf the inheritance is public then The private members are not inherited The public members of base class becomes public in derive classThe protected members of base class becomes protected in derived class
class A{
private: int a;protected: int b;public: int c;
};Class B: public A{
private: int x;};
The member accessible in derive class B are
b protectedc publicx private
![Page 6: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/6.jpg)
6
InheritancePrivate inheritanceIf the inheritance is private then The private members are not inherited The public members of base class becomes private in derive classThe protected members of base class becomes private in derived class
class A{
private: int a;protected: int b;public: int c;
};class B: private A{
private: int x;};
The member accessible in derive class B areb privatec privatex private
![Page 7: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/7.jpg)
7
InheritanceProtected inheritanceIf the inheritance is protected then The private members are not inherited The public members of base class becomes protected in derive classThe protected members of base class becomes protected in derived class
class A{
private: int a;protected: int b;public: int c;
};class B: protected A{
private: int x;};
The member accessible in derive class B are
b protectedc protectedx private
![Page 8: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/8.jpg)
8
InheritanceVisibility of inherited members
Base class
Derived class
Public Private Protected
Derivation Derivation Derivation
Private Not Inherited Not Inherited Not Inherited
Protected Protected Private Protected
Public Public Private Protected
![Page 9: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/9.jpg)
9
InheritanceClass A
PrivateProtectedPublic
![Page 10: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/10.jpg)
10
InheritanceClass A
PrivateProtectedPublic
Class B : public APrivateProtectedPublic
Cannot inheritCannot inherit
![Page 11: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/11.jpg)
11
InheritanceClass A
PrivateProtectedPublic
Class B : public APrivateProtectedPublic
Cannot inheritCannot inherit
![Page 12: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/12.jpg)
12
InheritanceClass A
PrivateProtectedPublic
Class B : public APrivateProtectedPublic
Class C : private APrivateProtectedPublic
12
Cannot inheritCannot inherit
![Page 13: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/13.jpg)
13
InheritanceClass A
PrivateProtectedPublic
Class B : public APrivateProtectedPublic
Class C : private APrivateProtectedPublic
13
Cannot inheritCannot inherit
![Page 14: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/14.jpg)
14
InheritanceClass A
PrivateProtectedPublic
Class B : public APrivateProtectedPublic
Class C : private APrivateProtectedPublic
Class D : protected CPrivateProtectedPublic
Cannot inheritCannot inherit
![Page 15: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/15.jpg)
15
InheritanceClass A
PrivateProtectedPublic
Class B : public APrivateProtectedPublic
Class C : private APrivateProtectedPublic
Class D : protected CPrivateProtectedPublic
Cannot inheritCannot inherit
![Page 16: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/16.jpg)
16
InheritanceClass A
PrivateProtectedPublic
Class B : public APrivateProtectedPublic
Class C : private APrivateProtectedPublic
Class D : protected CPrivateProtectedPublic
Class E: private B,public CPrivateProtectedPublic
Cannot inheritCannot inherit
![Page 17: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/17.jpg)
17
InheritanceClass A
PrivateProtectedPublic
Class B : public APrivateProtectedPublic
Class C : private APrivateProtectedPublic
Class D : protected CPrivateProtectedPublic
Class E: private B,public CPrivateProtectedPublic
Cannot inheritCannot inherit
![Page 18: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/18.jpg)
18
InheritanceTypes of InheritanceThere are five different inheritances supported in C++:(1) Simple / Single(2) Multiple(3) Hierarchical(4) Multilevel(5) Hybrid
![Page 19: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/19.jpg)
19
InheritanceSingle Inheritance
A
B
![Page 20: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/20.jpg)
20
InheritanceMultiple Inheritance
C
A B
![Page 21: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/21.jpg)
21
InheritanceHierarchical Inheritance
A
B C
![Page 22: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/22.jpg)
22
InheritanceMulti level Inheritance
B
C
A
![Page 23: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/23.jpg)
23
InheritanceHybrid Inheritance
Combination of Hierarchical & Multiple A
B C
D
![Page 24: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/24.jpg)
24
Inheritance
![Page 25: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/25.jpg)
25
Inheritance
![Page 26: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/26.jpg)
26
Inheritance
![Page 27: Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class](https://reader038.vdocument.in/reader038/viewer/2022103122/56649d0b5503460f949def0e/html5/thumbnails/27.jpg)
27
Inheritance