+ 1

What is "destructor"

question in challege : Can a destructor take arguments ?

13th Apr 2017, 4:50 PM
ŠŠ“хŠ°Š¼ Ā«MooNWalkeRĀ» ŠŠ±Š“уŠ²Š°Ń…ŠøŠ“Š¾Š²
ŠŠ“хŠ°Š¼ Ā«MooNWalkeRĀ» ŠŠ±Š“уŠ²Š°Ń…ŠøŠ“Š¾Š² - avatar
5 Answers
+ 4
there is a destructor in c# tho, which is similar to java
13th Apr 2017, 7:55 PM
Edward
+ 3
opposite of constructor
13th Apr 2017, 4:53 PM
Muhammad Mujtaba
Muhammad Mujtaba - avatar
+ 3
in Java, there is no destructor instead you can use finalize or close
13th Apr 2017, 5:00 PM
Muhammad Mujtaba
Muhammad Mujtaba - avatar
+ 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
13th Apr 2017, 5:03 PM
Joshua Pierson
Joshua Pierson - avatar
+ 1
And no the destructor (at least in c++) does not take arguments
13th Apr 2017, 5:04 PM
Joshua Pierson
Joshua Pierson - avatar