What is the difference between constructor and destructor?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is the difference between constructor and destructor??

24th May 2017, 1:36 PM
Sasirekha
Sasirekha - avatar
6 Answers
+ 4
constructor is used to initialize the instance of class as he said. and destructor is when the object is deleted or destroyed which is no longer in needed
24th May 2017, 1:45 PM
Sasirekha
Sasirekha - avatar
+ 2
A constructor is called when a class is created. A destructor is called when a class is destroyed.
24th May 2017, 1:38 PM
Caleb Jore
Caleb Jore - avatar
+ 2
this is not an exact answer
24th May 2017, 1:39 PM
Sasirekha
Sasirekha - avatar
+ 2
Constructor is a special member function whose task is to initialise an object of it's class. & Destructor is a special member function whose task is to destroy the object created by constructor. Which gets called automatically when program ends.
24th Apr 2018, 12:55 PM
Jayesh Patil
Jayesh Patil - avatar
+ 1
That's all I know about it. Please refer to the Q&A or the the course you took for answers.
24th May 2017, 1:41 PM
Caleb Jore
Caleb Jore - avatar
- 1
constructor is used when we want to execute some fuction after runtime...
24th May 2017, 4:07 PM
Zeeshan Salam
Zeeshan Salam - avatar