Subscribe:

Labels

Tuesday, February 9, 2010

constructor and destructor

#include <iostream>
#include <iostream.h>

#include <conio.h>

class myclass {

int a,b;

public:

myclass();                   // constructor

~myclass();                  // destructor

void show();

};





myclass::myclass()

{

cout << "In constructor\n";

a = 10;

b = 20;

}

myclass::~myclass()

{

cout << "Destructing...\n";

}



void myclass::show()

{

cout << "A ="  << a << endl << "B =" << b << endl;

cout << "Sum is " << a+b << endl;

}



int main()

{

clrscr();



myclass ob;



ob.show();



return 0;

}

No comments:

Post a Comment