0% found this document useful (0 votes)
3 views10 pages

oopm ppt

The document presents an introduction to inheritance in C++, highlighting its significance in Object Oriented Programming. It covers the syntax of inheritance, types of inheritance including single, multilevel, multiple, hierarchical, and hybrid inheritance, along with examples for single and multilevel inheritance. The document serves as a foundational guide for understanding how classes can derive properties from other classes in C++.

Uploaded by

sourabhjatav10
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)
3 views10 pages

oopm ppt

The document presents an introduction to inheritance in C++, highlighting its significance in Object Oriented Programming. It covers the syntax of inheritance, types of inheritance including single, multilevel, multiple, hierarchical, and hybrid inheritance, along with examples for single and multilevel inheritance. The document serves as a foundational guide for understanding how classes can derive properties from other classes in C++.

Uploaded by

sourabhjatav10
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/ 10

ABCA-2

PPT PRESENTATIOM
TOPIC :- introduction of inheritance
Subject Code:- CD 305

Submitted to : Submitted BY :
SORABH JATAV
Mr.vijayprakash 0905CE231018
sharma
 INTRODUCTION OF INHERITANCE

The capability of a class to derive properties and characteristics from


another class is called Inheritance. Inheritance is one of the most
important features of Object Oriented Programming in C++. In this
article, we will learn about inheritance in C++, its modes and types along
with the information about how it affects different properties of the
class.

2
SYNTAX OF INHERITANCE IN C++

class derived_class_name : access-specifier base_class_name


{
// body ....
};

• class: keyword to create a new class


• derived_class_name: name of the new class, which will inherit the base class
• access-specifier: Specifies the access mode which can be either of private, public or
protected. If neither is specified, private is taken as default.
• base-class-name: name of the base class.

3
 TYPES OF INHERITANCE

The inheritance can be classified on the basis of the relationship


between the derived class and the base class. In C++, we have 5
types of inheritances:
Single inheritance

Multilevel inheritance

Multiple inheritance

Hierarchical inheritance

Hybrid inheritance

4
 SINGLE INHERITANCE

In single inheritance, a class is allowed to inherit from only


one class. i.e. one base class is inherited by one derived
class only.

5
SYNTAX OF SINGLE HERITANCE

class A
{
... .. ...
};
class B: public A
{
... .. ...
};

6
 EXAMPLE
1. #include <iostream>
2. using namespace std;
3.
4. class Vehicle {
5. public:
Output
6. Vehicle() { cout << "This is a Vehicle\n"; }
7. };
8. This is a Vehicle
9. class Car : public Vehicle { This Vehicle is Car
10. public:
11. Car() { cout << "This Vehicle is Car\n"; }
12. };
13.
14. int main()
15. {
16. Car obj;
17. return 0;
}
7
 Multilevel Inheritance

In this type of inheritance, a derived class is created from another


derived class and that derived class can be derived from a base
class or any other derived class. There can be any number of levels

8
 Syntax of multilevel inheritance

class C
{
... .. ...
};
class B : public C
{
... .. ...
};
class A: public B
{
... ... ...
};

9
 Example
#include <iostream>
using namespace std;

class Vehicle {
public:
Vehicle() { cout << "This is a Vehicle\n"; }
};

class fourWheeler : public Vehicle {


public:
fourWheeler() { cout << "4 Wheeler Vehicles\n"; }
};

fourWheeler
class Car : public fourWheeler {
public:
Car() { cout << "This 4 Wheeler Vehical is a Car\n"; }
};

int main()
{
Car obj;
return 0;
10
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy