SlideShare a Scribd company logo
CONSTUCTOR & DESTRUCTORSCONSTUCTOR & DESTRUCTORS
OBJECT ORIENTED PROGRAMMINGOBJECT ORIENTED PROGRAMMING
INDEX
Concept of constructor, types of constructorConcept of constructor, types of constructor
Overloaded constructor
Destructor
1
2
3
CONCEPT OF CONSTRUCTOR
• A constructor is a special member function
whose task is to initialize the objects of that
class.
• It is special because its name is the same as
the class name.
• Constructor is invoked whenever an object of
the associated class is created.
• It is called constructor because it constructs
the values of data members of the class.
TYPES OF CONSTRUCTOR
• Default constructor:
A constructor that accepts no parameters is called
the default constructor.
• Parameterized constructor:
The constructor that can take arguments is called as
parameterized constructor.
• Copy constructor:
a constructor can accept a reference to its own class
as a parameter which is called as copy constructor.
OVERLOADED CONSTRUCTOR
• When more than one constructor function is
defined in a class, we say the constructor is
overloaded.
DESTRUCTOR
• A destructor, as the name implies is used to
destroy the objects that have been created by
a constructor.
• Like a constructor, the destructor is also a
special member function whose name is the
same as the class name but is preceded by a
tilde(~).
• Example: the destructor for class integer can
be defined as shown below
~integer() {}
DESTRUCTOR
• A destructor, as the name implies is used to
destroy the objects that have been created by
a constructor.
• Like a constructor, the destructor is also a
special member function whose name is the
same as the class name but is preceded by a
tilde(~).
• Example: the destructor for class integer can
be defined as shown below
~integer() {}

More Related Content

What's hot

Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
Hirra Sultan
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
Tamanna Akter
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
Ronak Chhajed
 
Major and Minor Elements of Object Model
Major and Minor Elements of Object ModelMajor and Minor Elements of Object Model
Major and Minor Elements of Object Model
sohailsaif
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
Vinod Kumar
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
ThamizhselviKrishnam
 
file handling c++
file handling c++file handling c++
file handling c++Guddu Spy
 
object oriented Programming ppt
object oriented Programming pptobject oriented Programming ppt
object oriented Programming ppt
Nitesh Dubey
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 

What's hot (20)

Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java Streams
Java StreamsJava Streams
Java Streams
 
class and objects
class and objectsclass and objects
class and objects
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Inner class
Inner classInner class
Inner class
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
OOP java
OOP javaOOP java
OOP java
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
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 OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Major and Minor Elements of Object Model
Major and Minor Elements of Object ModelMajor and Minor Elements of Object Model
Major and Minor Elements of Object Model
 
Input output streams
Input output streamsInput output streams
Input output streams
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
file handling c++
file handling c++file handling c++
file handling c++
 
object oriented Programming ppt
object oriented Programming pptobject oriented Programming ppt
object oriented Programming ppt
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 

Similar to constructor and destructor-object oriented programming

Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
murugeswariSenthilku
 
C++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptxC++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptx
sasukeman
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
Constructor and destructor in oop
Constructor and destructor in oop Constructor and destructor in oop
Constructor and destructor in oop
Samad Qazi
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
Sunipa Bera
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Prof. Dr. K. Adisesha
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
aleenaguen
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
SIVASHANKARIRAJAN
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
sunilchute1
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
rajshreemuthiah
 
Constructors & Destructors
Constructors  & DestructorsConstructors  & Destructors
Constructors & Destructors
Rokonuzzaman Rony
 
Constructor and desturctor
Constructor and desturctorConstructor and desturctor
Constructor and desturctorSomnath Kulkarni
 
DHARANI.pptx
DHARANI.pptxDHARANI.pptx
DHARANI.pptx
DharaniG29
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
Saharsh Anand
 
C++ Constructor destructor
C++ Constructor destructorC++ Constructor destructor
C++ Constructor destructor
Da Mystic Sadi
 
What is Constructors and Destructors in C++ (Explained with Example along wi...
What is Constructors and Destructors in  C++ (Explained with Example along wi...What is Constructors and Destructors in  C++ (Explained with Example along wi...
What is Constructors and Destructors in C++ (Explained with Example along wi...
Pallavi Seth
 
Java ConstructorsPPT.pptx
Java ConstructorsPPT.pptxJava ConstructorsPPT.pptx
Java ConstructorsPPT.pptx
XanGwaps
 
Constructor
ConstructorConstructor
Constructor
Jadavsejal
 
C++
C++C++
C++
C++C++

Similar to constructor and destructor-object oriented programming (20)

Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
C++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptxC++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptx
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Constructor and destructor in oop
Constructor and destructor in oop Constructor and destructor in oop
Constructor and destructor in oop
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
Constructors & Destructors
Constructors  & DestructorsConstructors  & Destructors
Constructors & Destructors
 
Constructor and desturctor
Constructor and desturctorConstructor and desturctor
Constructor and desturctor
 
DHARANI.pptx
DHARANI.pptxDHARANI.pptx
DHARANI.pptx
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
 
C++ Constructor destructor
C++ Constructor destructorC++ Constructor destructor
C++ Constructor destructor
 
What is Constructors and Destructors in C++ (Explained with Example along wi...
What is Constructors and Destructors in  C++ (Explained with Example along wi...What is Constructors and Destructors in  C++ (Explained with Example along wi...
What is Constructors and Destructors in C++ (Explained with Example along wi...
 
Java ConstructorsPPT.pptx
Java ConstructorsPPT.pptxJava ConstructorsPPT.pptx
Java ConstructorsPPT.pptx
 
Constructor
ConstructorConstructor
Constructor
 
C++
C++C++
C++
 
C++
C++C++
C++
 

More from Ashita Agrawal

Linux operating system - Overview
Linux operating system - OverviewLinux operating system - Overview
Linux operating system - Overview
Ashita Agrawal
 
Introductio to Abstract Window Toolkit (AWT)
Introductio to Abstract Window Toolkit (AWT)Introductio to Abstract Window Toolkit (AWT)
Introductio to Abstract Window Toolkit (AWT)
Ashita Agrawal
 
INTRODUCTION TO UML DIAGRAMS
INTRODUCTION TO UML DIAGRAMSINTRODUCTION TO UML DIAGRAMS
INTRODUCTION TO UML DIAGRAMS
Ashita Agrawal
 
Introduction to Sets
Introduction to SetsIntroduction to Sets
Introduction to Sets
Ashita Agrawal
 
Business Overview
Business OverviewBusiness Overview
Business Overview
Ashita Agrawal
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
Ashita Agrawal
 
Biography of Mahatma Gandhi : 1869-1948
Biography of Mahatma Gandhi : 1869-1948Biography of Mahatma Gandhi : 1869-1948
Biography of Mahatma Gandhi : 1869-1948
Ashita Agrawal
 
Cloud computing - new class of network based computing
Cloud computing - new class of network based computingCloud computing - new class of network based computing
Cloud computing - new class of network based computing
Ashita Agrawal
 
Introduction to computer network
Introduction to computer networkIntroduction to computer network
Introduction to computer network
Ashita Agrawal
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
Ashita Agrawal
 
Testing Machine- universal tester
Testing Machine- universal testerTesting Machine- universal tester
Testing Machine- universal tester
Ashita Agrawal
 
Adolf Hitler - German politician(world war I)
Adolf Hitler - German politician(world war I)Adolf Hitler - German politician(world war I)
Adolf Hitler - German politician(world war I)
Ashita Agrawal
 
Charles babbage - Father of Computing.
Charles babbage - Father of Computing. Charles babbage - Father of Computing.
Charles babbage - Father of Computing.
Ashita Agrawal
 
Ada Lovelace-The First Programmer
Ada Lovelace-The First ProgrammerAda Lovelace-The First Programmer
Ada Lovelace-The First Programmer
Ashita Agrawal
 
Slums In India
Slums In IndiaSlums In India
Slums In India
Ashita Agrawal
 
Augmented Reality
Augmented RealityAugmented Reality
Augmented Reality
Ashita Agrawal
 

More from Ashita Agrawal (16)

Linux operating system - Overview
Linux operating system - OverviewLinux operating system - Overview
Linux operating system - Overview
 
Introductio to Abstract Window Toolkit (AWT)
Introductio to Abstract Window Toolkit (AWT)Introductio to Abstract Window Toolkit (AWT)
Introductio to Abstract Window Toolkit (AWT)
 
INTRODUCTION TO UML DIAGRAMS
INTRODUCTION TO UML DIAGRAMSINTRODUCTION TO UML DIAGRAMS
INTRODUCTION TO UML DIAGRAMS
 
Introduction to Sets
Introduction to SetsIntroduction to Sets
Introduction to Sets
 
Business Overview
Business OverviewBusiness Overview
Business Overview
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Biography of Mahatma Gandhi : 1869-1948
Biography of Mahatma Gandhi : 1869-1948Biography of Mahatma Gandhi : 1869-1948
Biography of Mahatma Gandhi : 1869-1948
 
Cloud computing - new class of network based computing
Cloud computing - new class of network based computingCloud computing - new class of network based computing
Cloud computing - new class of network based computing
 
Introduction to computer network
Introduction to computer networkIntroduction to computer network
Introduction to computer network
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
 
Testing Machine- universal tester
Testing Machine- universal testerTesting Machine- universal tester
Testing Machine- universal tester
 
Adolf Hitler - German politician(world war I)
Adolf Hitler - German politician(world war I)Adolf Hitler - German politician(world war I)
Adolf Hitler - German politician(world war I)
 
Charles babbage - Father of Computing.
Charles babbage - Father of Computing. Charles babbage - Father of Computing.
Charles babbage - Father of Computing.
 
Ada Lovelace-The First Programmer
Ada Lovelace-The First ProgrammerAda Lovelace-The First Programmer
Ada Lovelace-The First Programmer
 
Slums In India
Slums In IndiaSlums In India
Slums In India
 
Augmented Reality
Augmented RealityAugmented Reality
Augmented Reality
 

Recently uploaded

Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 

Recently uploaded (20)

Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 

constructor and destructor-object oriented programming

  • 1. CONSTUCTOR & DESTRUCTORSCONSTUCTOR & DESTRUCTORS OBJECT ORIENTED PROGRAMMINGOBJECT ORIENTED PROGRAMMING
  • 2. INDEX Concept of constructor, types of constructorConcept of constructor, types of constructor Overloaded constructor Destructor 1 2 3
  • 3. CONCEPT OF CONSTRUCTOR • A constructor is a special member function whose task is to initialize the objects of that class. • It is special because its name is the same as the class name. • Constructor is invoked whenever an object of the associated class is created. • It is called constructor because it constructs the values of data members of the class.
  • 4. TYPES OF CONSTRUCTOR • Default constructor: A constructor that accepts no parameters is called the default constructor. • Parameterized constructor: The constructor that can take arguments is called as parameterized constructor. • Copy constructor: a constructor can accept a reference to its own class as a parameter which is called as copy constructor.
  • 5. OVERLOADED CONSTRUCTOR • When more than one constructor function is defined in a class, we say the constructor is overloaded.
  • 6. DESTRUCTOR • A destructor, as the name implies is used to destroy the objects that have been created by a constructor. • Like a constructor, the destructor is also a special member function whose name is the same as the class name but is preceded by a tilde(~). • Example: the destructor for class integer can be defined as shown below ~integer() {}
  • 7. DESTRUCTOR • A destructor, as the name implies is used to destroy the objects that have been created by a constructor. • Like a constructor, the destructor is also a special member function whose name is the same as the class name but is preceded by a tilde(~). • Example: the destructor for class integer can be defined as shown below ~integer() {}