Tuesday 24 February 2015

Constructor OverLoading in C++

/*
Constructor and Constructor OverLoading
=======================================
*/
#include<iostream.h>
#include<conio.h>

class Date
{
private:
int dd,mm,yy;
public:
Date()  /* Default Constructor */
{
dd=11;
mm=2;
yy=2005;
}
Date(int d,int m,int y)     /* Three Argument Constructor */
{
dd=d;
mm=m;
yy=y;
}
void Display()
{
cout<<"\n ToDay Date is\n";
cout<<dd<<"\\"<<mm<<"\\"<<yy;
}
};
void main()
{
clrscr();
Date d; /* Default Constructor is Called Automatically*/
d.Display();

Date d1(22,2,2005); /* Three Argument Constructor is Called */
d1.Display();
getch();
}

No comments:

Post a Comment