Write a program to show the constructor overloading at the version of constructor in available in a class.

class OverLoad
  {
    int age, num1,num2,num3,sum,e,b,c;
    String name;
    OverLoad(String n,int a) //constructor
    {
      name=n;
      age=a;
    }
    void disp()
     {
      System.out.println("Name of the person  :"+name);
      System.out.println("age  of the person  :"+age);
     }
   
    OverLoad(int e,int b,int c)
    {
     num1=e;
     num2=b;
     num3=c;
    
    }
   
     void show()
     {
       int sum=num1+num2+num3;
       System.out.println("sum  =:"+sum);
     }
  public static void main(String args[])
    {
       OverLoad ob=new OverLoad("kapil" ,19);

      
       ob.disp();
       OverLoad ab=new OverLoad(4,5,6);
       ab.show();
    }
 }
     

     

No comments:

Post a Comment