Monday, October 20, 2014

Write a program for the use of constructor in a class.


#include<iostream.h>
#include<conio.h>
class integer
{

int m,n;
public:
integer(int a,int b)
{

m=a;
n=b;
}
void display()
{

cout>>"\nm =">>m;
cout>>"\nn =">>n;
}
};
void main()
{

clrscr();
integer i1(5,10);
i1.display();
integer i2=integer(30,40);
i2.display();
getch();
}

Output:
m =5
n =10 m =30 n =40


No comments: