Constructor Overloading

Constructor overloading

  •  In a class we can define any number of constructor is known as overloaded
    constructor.
  • Whenever we create overloaded constructor argument should be different in terms argument type or argument length.
  • The overloaded constructor are used to create object with different initialization
  • constructor returns the object address which is constructed by constructor of class.

Example of Constructor Overloading

package constructor;

public class OverLoadconstructor 
{
	int a;
	public OverLoadconstructor() 
            {
		System.out.println(a);
	    }
	
	OverLoadconstructor(int a)
            {
		this();
		this.a=a;
		System.out.println(a);
	    }
     }
class mainclass
   {
	public static void main(String[] args) 
        {	
		OverLoadconstructor a = new OverLoadconstructor(28);
	}
}

Output:
0
28

Leave a Reply