Simple Example of Constructor
#include<iostream.h>
#include<conio.h>
class mahi
{
int m,n;
public:
mahi(int,int);
void display()
{
cout<<"\n m= "<<m;
cout<<"\n n= "<<n;
}
};
mahi::mahi(int x,int y)
{
m=x;
n=y;
}
void main()
{
clrscr();
mahi m1(10,20);
mahi m2(30,40);
cout<<"\n\n OBJECT1\n";
m1.display();
cout<<"\n\n OBJECT2\n";
m2.display();
getch();
}
Here is the Output :)
No comments:
Post a Comment