Write a program in java to demonstrate Constructor overloading.
Program:-
package const;
public static void main(String[] args) {
// TODO Auto-generated method stub
show r1=new show(10);
r1.put1();
show r2=new show(10,20);
r2.put2();
show r3=new show(11,22,33);
r3.put3();
}
}
class
show
{
public
int a,b,c;
public show(int x)
{
a=x;
}
public show(int a1, int b1)
{
a=a1;
b=b1;
}
public show(int a1, int b1, int c1)
{
a=a1;
b=b1;
c=c1;
}
void put1()
{
System.out.println("The value of a is: "+a);
}
void put2()
{
System.out.println("The value of a and bis: "+a+" "+b);
System.out.println("The Addition of a and b is: "+(a+b));
}
void put3()
{
System.out.println("The value of a, b and c is: "+a+" "+b+" "+c);
System.out.println("The Addition of a,b and b is: "+(a+b+c));
}
}
Output:-
The
value of a is: 10
The
value of a and bis: 10 20
The
Addition of a and b is: 30
The
value of a, b and c is: 11 22 33
The
Addition of a,b and b is: 66