Constructor overloading

Programming example for Constructor overloading

           public class constructor {

           int reg_no;

          string name;

           constructor()

{

        System.out.println("this is default constructor");

}   

       constructor(int i,string n)

{

     reg_no=i;

      name=n;

}

     constructor (constructor s)

{

      reg_no=s.reg_no;

      name=s.name;

}

     void display()

{

      System.out.println(reg_no+ " '+name);

}

     public static void main(string args[]) {

     constructor s = new constructor();

     constructor s1 = new constructor( 12,"likhitha");

     constructor s2 = new constructor(s1);

      constructor s3 = s1;

      s2.reg_no=s1.reg_no;

      s2.name=s1.name;

       s1.display();

       s2.display();

        s3.display();

     }

}

Posted on by