source code name: constrc1.cpp
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class simple
{
int a,b;
public:
simple()
{
a=b=0;
}
simple(int m, int n)
{
a=m;
b=n;
}
void show()
{
cout<<"\n a "<<a<<" b: "<<b;
}
} ;
void main()
{
clrscr();
cout<<"Constructor program: ";
simple ob1, ob2(10,20);
cout<<" object 1 data: ";
ob1.show();
cout<<" \n object 2 data: ";
ob2.show();
getch();
}
output:
Constructor program:
object 1 data:
a: 0 b: 0
object 2 data:
a: 10 b: 20
0 Comments
Post a Comment