Programming Pandit

c/c++/c#/Javav/Python


Latest Update

Thursday, August 15, 2024

C++ Program for Destructor.

Objective:  Write a C++ Program to implement the use of a Destructor.


Code :

#include <iostream>

using namespace std;

class Demo 

{

public:

    // Constructor

    Demo() 

{

        cout << "Constructor: Object is created." << std::endl;

    }

    // Destructor

    ~Demo() 

{

        cout << "Destructor: Object is destroyed." << std::endl;

    }

};

int main() 

{

    // Create an object of the Demo class

    Demo obj;    

    // Destructor will be called automatically when the object goes out of scope

    return 0;

}


Output :




No comments:

Post a Comment