SlideShare a Scribd company logo
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Subject- Object Oriented Programming (CO212)
Unit 2 – Overloading and Inheritance
Topic – 2.8 Constructor and Destructor in Inheritance
Prof. V.N.Nirgude
Assistant Professor
E-mail :
nirgudevikascomp@sanjivani.org.i
Contact No: 9975240215
Constructor and Destructor in Inheritance
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 2
• Invocation of constructors and destructors depends on the type of inheritance
being implemented.
Constructor and destructor in single inheritance:
• Base class constructors are called first and the derived class constructors are
called next in single inheritance.
• Destructor is called in reverse sequence of constructor invocation i.e. The
destructor of the derived class is called first and the destructor of the base class is
called next.
class base derived() Output :
{ { base class constructor
public: cout<<"derived class constructor"; derived class constructor
base() } derived class destructor
{ ~derived() base class destructor
cout<<"base class constructor"; {
} cout<<"derived class destructor";
~base() }
{
cout<<"base class destructor"; };
} int main()
}; {
class derived: public base derived d;
{
public:
}
Example of Constructor and Destructor in Single Inheritance
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 3
Constructor and destructor in multiple inheritance
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 4
• Constructors from all base classes are invoked first and then derived
class constructor is called.
• Order of constructor invocation depends on the order of how base
classess are inherited.
• For example:
• class D:public B, public C { //… }
• Here, B is inherited first, so the constructor of class B is called first
and then constructor of class C is called next.
• However, the destructor of derived class is called first and then
destructor of the base class which is mentioned in the derived class
declaration is called from last towards first in sequentially.
Example of constructor and destructor in multiple inheritance
class base_one
{
public:
base_one()
{
cout<<"base_one class constructor";
}
~base_one()
{
cout<<"base_one class destructor";
}
};
class base_two
{
public:
base_two()
{
cout<<"base_two class constructor";
}
~base_two()
{
cout<<"base_two class destructor";
}
};
class derived: public base_one, public
base_two
{
public:
derived()
{
cout<<"derived class constructor";
}
~derived()
{
cout<<"derived class destructor";
}
};
int main()
{
derived d;
return 0;
}
Output :
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 5
Thank you..
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 6

More Related Content

PPTX
Inheritance_PART2.pptx
PDF
Constructor & destructor
PDF
1.11 Constructors and Destructors....pdf
PPT
Oop Constructor Destructors Constructor Overloading lecture 2
PPTX
Constructor and desturctor
PPTX
asic computer is an electronic device that can receive, store, process, and o...
PPT
5 Constructors and Destructors
PDF
C++ prgms 5th unit (inheritance ii)
Inheritance_PART2.pptx
Constructor & destructor
1.11 Constructors and Destructors....pdf
Oop Constructor Destructors Constructor Overloading lecture 2
Constructor and desturctor
asic computer is an electronic device that can receive, store, process, and o...
5 Constructors and Destructors
C++ prgms 5th unit (inheritance ii)

Similar to 2.8 Constructor and Destructor in Derived Class.pdf (20)

PDF
Constructor & destructor
PPT
constructors and destructors in c++ language.ppt
PPTX
Inheritance
PPT
Friend this-new&delete
PPT
ConsTRUCTION AND DESTRUCTION
PPTX
Inheritance, Polymorphism, and Virtual Functions (Ch_15).pptx
PPTX
Week 3 - OOP Constructor (1)classtas.pptx
PPTX
object oriented programming with C++ Constructors_Destructors.pptx
PPTX
Constructor and destructor in oop
PPTX
Constructors in C++.pptx
PPTX
Constructor and Destructor
PPTX
Constructors and Destructors
PPTX
CS1Lesson15-Inheritance (1).pptx
PPTX
CS1Lesson15-Inheritance in c++ programmming language.pptx
PPTX
CS1Lesson15-Inheritance.pptx
PPTX
Constructor & destructor
PPTX
constructocvbcvbcvbcvbr-Destructor (1).pptx
PPT
constructor-.pptcucfkifkficuvguvucufjfugugigig
PPTX
constructor & destructor in cpp
PPTX
constructor & destructor in cpp
Constructor & destructor
constructors and destructors in c++ language.ppt
Inheritance
Friend this-new&delete
ConsTRUCTION AND DESTRUCTION
Inheritance, Polymorphism, and Virtual Functions (Ch_15).pptx
Week 3 - OOP Constructor (1)classtas.pptx
object oriented programming with C++ Constructors_Destructors.pptx
Constructor and destructor in oop
Constructors in C++.pptx
Constructor and Destructor
Constructors and Destructors
CS1Lesson15-Inheritance (1).pptx
CS1Lesson15-Inheritance in c++ programmming language.pptx
CS1Lesson15-Inheritance.pptx
Constructor & destructor
constructocvbcvbcvbcvbr-Destructor (1).pptx
constructor-.pptcucfkifkficuvguvucufjfugugigig
constructor & destructor in cpp
constructor & destructor in cpp
Ad

More from VikasNirgude2 (20)

PDF
4.2 Class Template, Template and Inheritance.pdf
PDF
Function Templates,Overlaoding Function Templates.pdf
PDF
Introduction to Inheritance and Its concepts
PDF
Data Conversion and Type Casting Concepts
PDF
Operator Overloading Introduction and Concept of OV
PDF
1.10 Functions in C++,call by value .pdf
PDF
1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...
PDF
1.7 Arrays in C++ and its detail........pdf
PDF
1.6 Control Structures in C++ .......pdf
PDF
1.5 Data Types in C++ and Its Details.pdf
PDF
C++ programming Basic and Operators of C++
PDF
1.3 Object Oriented Programming Paradigm, Basic Concepts of Object-Oriented P...
PDF
1.2 Need of Object-Oriented Programming.pdf
PDF
1.1 Introduction to procedural, modular, object-oriented and generic programm...
PDF
B Tree, Introduction ,example,Splay tree
PPT
Tree-introduction ,Definition, Types of BT
PPTX
Double Hashing.pptx
PPTX
closed hashing.pptx
PPTX
Collision resolution.pptx
PPTX
closed hashing.pptx
4.2 Class Template, Template and Inheritance.pdf
Function Templates,Overlaoding Function Templates.pdf
Introduction to Inheritance and Its concepts
Data Conversion and Type Casting Concepts
Operator Overloading Introduction and Concept of OV
1.10 Functions in C++,call by value .pdf
1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...
1.7 Arrays in C++ and its detail........pdf
1.6 Control Structures in C++ .......pdf
1.5 Data Types in C++ and Its Details.pdf
C++ programming Basic and Operators of C++
1.3 Object Oriented Programming Paradigm, Basic Concepts of Object-Oriented P...
1.2 Need of Object-Oriented Programming.pdf
1.1 Introduction to procedural, modular, object-oriented and generic programm...
B Tree, Introduction ,example,Splay tree
Tree-introduction ,Definition, Types of BT
Double Hashing.pptx
closed hashing.pptx
Collision resolution.pptx
closed hashing.pptx
Ad

Recently uploaded (20)

PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Geodesy 1.pptx...............................................
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT
introduction to datamining and warehousing
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
web development for engineering and engineering
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
PPT on Performance Review to get promotions
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
additive manufacturing of ss316l using mig welding
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Well-logging-methods_new................
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Geodesy 1.pptx...............................................
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
introduction to datamining and warehousing
R24 SURVEYING LAB MANUAL for civil enggi
Lecture Notes Electrical Wiring System Components
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
web development for engineering and engineering
Foundation to blockchain - A guide to Blockchain Tech
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT on Performance Review to get promotions
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
additive manufacturing of ss316l using mig welding
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
CH1 Production IntroductoryConcepts.pptx
Well-logging-methods_new................
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Automation-in-Manufacturing-Chapter-Introduction.pdf

2.8 Constructor and Destructor in Derived Class.pdf

  • 1. Sanjivani Rural Education Society’s Sanjivani College of Engineering, Kopargaon-423 603 (An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune) NAAC ‘A’Grade Accredited, ISO 9001:2015 Certified Department of Computer Engineering (NBA Accredited) Subject- Object Oriented Programming (CO212) Unit 2 – Overloading and Inheritance Topic – 2.8 Constructor and Destructor in Inheritance Prof. V.N.Nirgude Assistant Professor E-mail : nirgudevikascomp@sanjivani.org.i Contact No: 9975240215
  • 2. Constructor and Destructor in Inheritance DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 2 • Invocation of constructors and destructors depends on the type of inheritance being implemented. Constructor and destructor in single inheritance: • Base class constructors are called first and the derived class constructors are called next in single inheritance. • Destructor is called in reverse sequence of constructor invocation i.e. The destructor of the derived class is called first and the destructor of the base class is called next.
  • 3. class base derived() Output : { { base class constructor public: cout<<"derived class constructor"; derived class constructor base() } derived class destructor { ~derived() base class destructor cout<<"base class constructor"; { } cout<<"derived class destructor"; ~base() } { cout<<"base class destructor"; }; } int main() }; { class derived: public base derived d; { public: } Example of Constructor and Destructor in Single Inheritance DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 3
  • 4. Constructor and destructor in multiple inheritance DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 4 • Constructors from all base classes are invoked first and then derived class constructor is called. • Order of constructor invocation depends on the order of how base classess are inherited. • For example: • class D:public B, public C { //… } • Here, B is inherited first, so the constructor of class B is called first and then constructor of class C is called next. • However, the destructor of derived class is called first and then destructor of the base class which is mentioned in the derived class declaration is called from last towards first in sequentially.
  • 5. Example of constructor and destructor in multiple inheritance class base_one { public: base_one() { cout<<"base_one class constructor"; } ~base_one() { cout<<"base_one class destructor"; } }; class base_two { public: base_two() { cout<<"base_two class constructor"; } ~base_two() { cout<<"base_two class destructor"; } }; class derived: public base_one, public base_two { public: derived() { cout<<"derived class constructor"; } ~derived() { cout<<"derived class destructor"; } }; int main() { derived d; return 0; } Output : DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 5
  • 6. Thank you.. DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 6