+ 1
What is "destructor"
question in challege : Can a destructor take arguments ?
5 Answers
+ 4
there is a destructor in c# tho, which is similar to java
+ 3
opposite of constructor
+ 3
in Java, there is no destructor instead you can use finalize or close
+ 1
It is a method(eg a function) that gets executed when an object(eg class object) gets destroyed. Below is an example.
#include <iostream>
using namespace std;
class Person
{
public:
Person()
{
cout << "Person is created" << endl;
}
~Person()
{
cout << "Person is destroyed" << endl;
}
};
int main()
{
//Person is our class name
//person1 is our object
//Here the constructor is called
Person person1;
//Here is a Person object that is called within an inline scope so it gets destroyed before the end of the program
{
//person 2 created (constructor called as a function)
Person person2;
}//person2 destroyed (destructor called as a function)
return 0;
};
//At the end of the main function all variables are destroyed and thus the destructor is called
+ 1
And no the destructor (at least in c++) does not take arguments