SlideShare a Scribd company logo
1 of 8
Destructer
NAME:- PRAJAPATI JAY R
ENROLLMENT NO:- 170950107074
CLASS/DIVISION:- CSE-B
SEMESTER:- 4TH
GUIDED BY:- ASTT.PROF.DHRUTI PANDYA
WHAT IS
DESTRUCTER?
• Destructor is a member function which destructs or deletes an object.
• Destructors are usually used to deallocate memory and do other cleanup
for a class object and its class members when the object is destroyed.
• A destructor is called for a class object when that object passes out of
scope or is explicitly deleted.
When is destructor
called?
• A destructor function is called automatically when the object goes out of
scope:
(1) the function ends
(2) the program ends
(3) a block containing local variables ends
(4) a delete operator is called
How destructors
are different from
a normal member
function?
• Destructors have same name as the class preceded by a tilde (~)
• Destructors don’t take any argument and don’t return anything
• If no user-defined destructor exists for a class and one is needed, the
compiler implicitly declares a destructor. This implicitly declared destructor
is an inline public member of its class.
• The compiler will implicitly define an implicitly declared destructor when
the compiler uses the destructor to destroy an object of the destructor's
class type. Suppose a class A has an implicitly declared destructor.
Rules:-
1) Name should begin with tilde sign(~) and must match
class name.
2) There cannot be more than one destructor in a class.
3) Unlike constructors that can have parameters,
destructors do not allow any parameter.
4) They do not have any return type, just like
constructors.
5) When you do not specify any destructor in a class,
compiler generates a default destructor and inserts it into
your code.
Structure:-
class class_name
{
public:
class_name(); //constructor.
~class_name(); //destructor.
}
Example:-
Code:- Output:-
Hey look I am in constructor
function main is terminating....
Hey look I am in destructor
Thanks

More Related Content

What's hot

Inner classes9 cm604.28
Inner classes9 cm604.28Inner classes9 cm604.28
Inner classes9 cm604.28
myrajendra
 

What's hot (20)

8. objects & classes
8. objects & classes8. objects & classes
8. objects & classes
 
Nested classes in java
Nested classes in javaNested classes in java
Nested classes in java
 
Access specifier
Access specifierAccess specifier
Access specifier
 
Inner classes
Inner classesInner classes
Inner classes
 
Nested class in java
Nested class in javaNested class in java
Nested class in java
 
[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance
 
Inner class
Inner classInner class
Inner class
 
Java Inner Class
Java Inner ClassJava Inner Class
Java Inner Class
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
OCAJP 8
OCAJP 8OCAJP 8
OCAJP 8
 
C# Access modifiers
C# Access modifiersC# Access modifiers
C# Access modifiers
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
Inner classes9 cm604.28
Inner classes9 cm604.28Inner classes9 cm604.28
Inner classes9 cm604.28
 
Learn Java Part 10
Learn Java Part 10Learn Java Part 10
Learn Java Part 10
 
Assigment 2
Assigment 2Assigment 2
Assigment 2
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
 
Keyword of java
Keyword of javaKeyword of java
Keyword of java
 
L5 classes, objects, nested and inner class
L5 classes, objects, nested and inner classL5 classes, objects, nested and inner class
L5 classes, objects, nested and inner class
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
 

Similar to Destructer

Java tutorials
Java tutorialsJava tutorials
Java tutorials
saryu2011
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objects
khaliledapal
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
lykado0dles
 

Similar to Destructer (20)

Destructors
DestructorsDestructors
Destructors
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
26c
26c26c
26c
 
26csharp
26csharp26csharp
26csharp
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Lecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptxLecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptx
 
Class and object
Class and objectClass and object
Class and object
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Better Understanding OOP using C#
Better Understanding OOP using C#Better Understanding OOP using C#
Better Understanding OOP using C#
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
oopm 2.pdf
oopm 2.pdfoopm 2.pdf
oopm 2.pdf
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objects
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
 
Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 

Recently uploaded

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 

Recently uploaded (20)

(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 

Destructer

  • 1. Destructer NAME:- PRAJAPATI JAY R ENROLLMENT NO:- 170950107074 CLASS/DIVISION:- CSE-B SEMESTER:- 4TH GUIDED BY:- ASTT.PROF.DHRUTI PANDYA
  • 2. WHAT IS DESTRUCTER? • Destructor is a member function which destructs or deletes an object. • Destructors are usually used to deallocate memory and do other cleanup for a class object and its class members when the object is destroyed. • A destructor is called for a class object when that object passes out of scope or is explicitly deleted.
  • 3. When is destructor called? • A destructor function is called automatically when the object goes out of scope: (1) the function ends (2) the program ends (3) a block containing local variables ends (4) a delete operator is called
  • 4. How destructors are different from a normal member function? • Destructors have same name as the class preceded by a tilde (~) • Destructors don’t take any argument and don’t return anything • If no user-defined destructor exists for a class and one is needed, the compiler implicitly declares a destructor. This implicitly declared destructor is an inline public member of its class. • The compiler will implicitly define an implicitly declared destructor when the compiler uses the destructor to destroy an object of the destructor's class type. Suppose a class A has an implicitly declared destructor.
  • 5. Rules:- 1) Name should begin with tilde sign(~) and must match class name. 2) There cannot be more than one destructor in a class. 3) Unlike constructors that can have parameters, destructors do not allow any parameter. 4) They do not have any return type, just like constructors. 5) When you do not specify any destructor in a class, compiler generates a default destructor and inserts it into your code.
  • 7. Example:- Code:- Output:- Hey look I am in constructor function main is terminating.... Hey look I am in destructor