0% found this document useful (0 votes)
70 views14 pages

Inheritance in C++

Inheritance in C++ allows a class to inherit properties from another class. The class that inherits is called the subclass or derived class, while the class it inherits from is called the base class or super class. Inheritance promotes code reuse and reduces redundancy. It allows software to develop faster, use less memory, and have better performance. There are different types of inheritance like single, multiple, hierarchical and multilevel inheritance. Inheritance also has modes like public, protected and private that determine which members are inherited.

Uploaded by

Noor Afshan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views14 pages

Inheritance in C++

Inheritance in C++ allows a class to inherit properties from another class. The class that inherits is called the subclass or derived class, while the class it inherits from is called the base class or super class. Inheritance promotes code reuse and reduces redundancy. It allows software to develop faster, use less memory, and have better performance. There are different types of inheritance like single, multiple, hierarchical and multilevel inheritance. Inheritance also has modes like public, protected and private that determine which members are inherited.

Uploaded by

Noor Afshan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Inheritance in C++

NOOR AFSHAN
What is Inheritance?

 The capability of a class to derive properties and characteristics from another


class is called Inheritance.
 Inheritance is one of the most important feature of Object Oriented
Programming.
Sub Class:
 The class that inherits properties from another class is called Sub class or Derived
Class.
Super Class:
 The class whose properties are inherited by sub class is called Base Class or Super
class.
Why and when to use Inheritance?

 Capability to express the inheritance relationship.


 Idea of reusability
 Transitive nature of inheritance
Advantages of Inheritance

 Software development time is less.


 Software take less memory.
 Code execution time is less.
 Code performance is enhance (improved).
 Redundancy (repetition) of the code is reduced or minimized so that we get
consistence results and less storage cost.
Real life example of inheritance
Example
Example
Modes of Inheritance

 Public mode: If we derive a sub class from a public base class. Then the public
member of the base class will become public in the derived class and protected
members of the base class will become protected in derived class. Private
members of the base class will never get inherited in sub class.
 Protected mode: If we derive a sub class from a Protected base class. Then both
public member and protected members of the base class will become protected in
derived class. Private members of the base class will never get inherited in sub class.
 Private mode: If we derive a sub class from a Private base class. Then both public
member and protected members of the base class will become Private in derived
class. Private members of the base class will never get inherited in sub class.
Modes of Inheritance
Types of Inheritance

 Single inheritance
 Multiple inheritance
 Hierarchical inheritance
 Multilevel inheritance
 Hybrid inheritance
Single Inheritance

 In single inheritance, a class is allowed to inherit


from only one class. i.e. one sub class is inherited
by one base class only.
 There exists single base class and single derived
class.
Syntax

class subclass_name : access_mode base_class


{
//body of subclass
};
Multiple Inheritance

You might also like