Java Program Function Overloading Example

This java code shows an example of time class with  function overloading.
class Time
{
                int h,m,s;
                void getdata()
                {
                                h=0;
                                m=0;
                                s=0;
                }
                void getdata(int a,int b,int c)
                {
                                h=a;
                                m=b;
                                s=c;
                }             
                void getdata(Time temp)
                {
                                h=temp.h;
                                m=temp.m;
                                s=temp.s;
                }             
                void disp()
                {
                                System.out.println(h + “:” + m + “:” + s);
                }
}
class Time_Demo2
{
                public static void main(String args[])
                {
                Time t1=new Time();
                Time t2=new Time();
                Time t3=new Time();
                t1.getdata(1,2,3);
                t2.getdata();
                t3.getdata(t1);
                t1.disp();
                t2.disp();
                t3.disp();
                }

}

Add Comment