#include <iostream>
class Demo{
    private:
    int value;

    public:
    Demo(){
        value=0;
        std::cout<<"Default constructor called\n";
    }
    Demo(int x)
{
    value=x;
    std::cout<<"Parameterized constructor called\n";
}
    Demo(const Demo &obj){
        value= obj.value;
        std::cout<<"Copy constructor called\n";
    }
    ~Demo(){
        std::cout<<"Destructor called for value\n"<<value<<"\n";
    }

};

int main(){
    std::cout<<"Creating object d1(default constructor):\n";

Demo d1;

std::cout<<"\n Creating object d2(parameterized constructor)\n";
Demo d2;

std::cout<<"\n Creating object d3(copy constructor)\n";
Demo d3 = d2;

std::cout<<"\n End of main , objects will be destroyed:\n";

return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: