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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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

Your email address will not be published. Required fields are marked *