Java Program using Constructor…

A simple java program showing use of a constructor.
class time
{
                int hrs,mins,secs;
                time()
                {
                                hrs=0;
                                mins=0;
                                secs=0;
                }
                time(int hr,int min,int sec)
                {
                                hrs=hr;
                                mins=min;
                                secs=sec;
                }
                void display()
                {
                                System.out.println(hrs + “:” + mins + “:” + secs + “:”);
                }
               
}
class T_time
{
                public static void main(String args[])
                {
                                time t=new time(5,23,7);
                                time t1=new time(4,45,40);
                                t.display();                         
                               
                }
}

Add Comment