Initializing the Class : Constructor

#include <iostream.h>
#include <conio.h>
class Time
{
private :
int hour;
int min;
public :
Time ( )
{
hour = min = 0;
}
Time ( int h, int m)
{
hour = h;
min = m;
}
void showTime()
{
cout<<hour<<” : “<<min<<”\n”;
}
};
void main( )
{
Time t1;
t1.showTime( );
Time t2(11,30);
t2.showTime();
}
Output :
0 : 0
11 : 30

0 comments: