SlideShare a Scribd company logo
1 of 37
Presentation Group Members :-
08. Ankita
14. Ashutosh
18. Samiksha
19. Laxman
S.Y.BSc.(Computer Science)
I
Types of Inheritance :-
Demo !!!!
Doubt & Question Session ????
Single
Inheritance
Multilevel
Inheritance
Multiple
Inheritance
Hierarchal
Inheritance
Hybrid
Inheritance
class base_class_name
{
access specifier:
:
};
Class derived_class_name : access specifier base_class_name
{
access specifier:
:
};
void A :: getdata ()
{
cout<<"nn Enter value
a:";
cin>>a;
cout<<"Enter value b:";
cin>>b;
}
void B :: calculate ()
{
c = (a + b);
}
void B :: display ()
{
cout<<"n"<<a<<"+"<<b<
<"="<<c;
}
Access Public Protected Private
Same class/
Base class
yes yes yes
Derived
classes
yes yes no
Outside
classes
yes no no
Public inheritance
Base access specifier
Derived access
specifier
Derived class access? Public access?
Public Public Yes Yes
Private Private No No
Protected Protected Yes No
Private inheritance
Base access specifier
Derived access
specifier
Derived class access? Public access?
Public Private Yes No
Private Private No No
Protected Private Yes No
Protected inheritance
Base access specifier
Derived access
specifier
Derived class access? Public access?
Public Protected Yes No
Private Private No No
Protected Protected Yes No
class derived class_name:<access_specifier>
class1_name,<access_specifier>
class2_name,………………………………………..,
<access_specifier> classn_name
{
:
: //members of derived class
:
}
SYNTAX:
class sub : public superA, private
superB
{
:
: //members of class sub
:
}
FOR INSTANCE:
Multilevel Inheritance :-
Definition:
“It is the inheritance hierarchy wherein subclass acts as a
base class for other classes”
It is implemented by defining at least three classes.
In multilevel inheritance, there is one base class and the
remaining two is derived class.
Declaration :-
class A
{………..
……….}; // Base class
class B : public A
{………..
……….}; // B derived from A
class C : public B
{……….
………}; // C derived from B
Fig. Multilevel Inheritance :-
Student
Test
Records
Result
Base Class
Intermediate
base class
Hybrid inheritance :-
Definition:
“Inheritance hierarchy that reflects any legal combination of
other four types of inheritance.”
Simple word:-
“The method of combining any two or more forms of
inheritance in single form is called hybrid inheritance.”
Fig. Hybrid Inheritance :-
Student
Test
Records
Result
Sports
Base
class
Intermediate
base class
Derived
class
Base
class
class A
{……….
………};
class B:public A
{……….
……….};
class C
{……….
………};
class D: public b, public c
{……….
……….};
Constructors in Inheritance :-
• Base class constructors are automatically called for you if
they have no argument.
• If you want to call a superclass constructor with an argument,
you must use the subclass's constructor initialization list.
• C++ supports multiple inheritance (for better or worse), so the
base class must be referred to by name, rather than "super()".
Constructor Example :-
class SuperClass
{
public:
SuperClass(int foo)
{ // do something with foo }
};
class SubClass : public SuperClass
{
public: SubClass(int foo, int bar) : SuperClass(foo)
{ // do something with bar }
};
Virtual keyword determines if a member function of a class can
be over-ridden in its derived classes.
The non-virtual member functions are resolved at compiling
time and it’s called static binding. However, the c++ virtual
member functions are resolved during runtime and it’s called
as dynamic binding
Virtual Class :-
For your Attention !!!!

More Related Content

What's hot

class and objects
class and objectsclass and objects
class and objects
Payel Guria
 

What's hot (20)

C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)Inheritance In C++ (Object Oriented Programming)
Inheritance In C++ (Object Oriented Programming)
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
class and objects
class and objectsclass and objects
class and objects
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 

Viewers also liked

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
Inheritance
InheritanceInheritance
Inheritance
Tech_MX
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
harshaltambe
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
file handling c++
file handling c++file handling c++
file handling c++
Guddu Spy
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
Baljit Saini
 

Viewers also liked (20)

Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
 
Inheritance
InheritanceInheritance
Inheritance
 
C++ Inheritance
C++ InheritanceC++ Inheritance
C++ Inheritance
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
file handling c++
file handling c++file handling c++
file handling c++
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphism
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
 
Inheritance Presentation
Inheritance PresentationInheritance Presentation
Inheritance Presentation
 
Inheritance
InheritanceInheritance
Inheritance
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 

Similar to Inheritance in C++

INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptxINHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
DeepasCSE
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
deepakskb2013
 

Similar to Inheritance in C++ (20)

12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
 
Inheritance and Interfaces
Inheritance and InterfacesInheritance and Interfaces
Inheritance and Interfaces
 
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptxINHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
INHERITANCE, POINTERS, VIRTUAL FUNCTIONS, POLYMORPHISM.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
MODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerMODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computer
 
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
 
c++Inheritance.pdf
c++Inheritance.pdfc++Inheritance.pdf
c++Inheritance.pdf
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
Inheritance
InheritanceInheritance
Inheritance
 
week14 (1).ppt
week14 (1).pptweek14 (1).ppt
week14 (1).ppt
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Ritik (inheritance.cpp)
Ritik (inheritance.cpp)Ritik (inheritance.cpp)
Ritik (inheritance.cpp)
 
Learn Java Part 11
Learn Java Part 11Learn Java Part 11
Learn Java Part 11
 
Learn Java Part 11
Learn Java Part 11Learn Java Part 11
Learn Java Part 11
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
Inheritance slides
Inheritance slidesInheritance slides
Inheritance slides
 
OOP
OOPOOP
OOP
 

More from Laxman Puri (7)

Remote access from a smartphone ppt
Remote access from a smartphone pptRemote access from a smartphone ppt
Remote access from a smartphone ppt
 
Processors
ProcessorsProcessors
Processors
 
Dbms rlde.ppt
Dbms rlde.pptDbms rlde.ppt
Dbms rlde.ppt
 
Co relation between dfd & event table
Co relation between dfd & event tableCo relation between dfd & event table
Co relation between dfd & event table
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 

Inheritance in C++