Friday, 24 August 2012

Constructor Overloading in C++

#include<iostream.h>
#include<conio.h>
class cse
{
int m,n;
public:
cse()
{
cout<<"\n the default constructor is executed";
}
cse(int a)
{
m=a;
cout<<"\n the value for a is..."<<m;
}
cse(int a,int b)
{
m=a+b;
cout<<"\n the sum of 20 and 30 is..."<<m;
}
~cse()
{
cout<<"\n destructor is executed";
}
cse(cse&i)
{
m=i.m;
cout<<"\n the value of m is"<<m;
}
};
void main()
{
clrscr();
cse a;
cse x(10);
cse y(20,30);
cse z(y);
getch();
}

No comments:

Post a Comment

There was an error in this gadget