Program to implement the concept of and destructor in C++
#include<iostream.h>
#include<conio.h>
class A
{ int x;
public :A() //creating a constructor
{
cout<<"\n EXecution in constructor";
}
public: ~A() //creating a destructor
{
cout<<"\n Execution in Destructor";
}};
int main()
{clrscr();
A* obj=new A; //making an object will call constructor automatically
delete obj; //deleting object will call destructor automatically
getch();
return 0;}
OutPut screen will look like this:-
No comments:
Post a Comment