Code:
Output:
class Overloading
{
int a , b ;
Overloading()
{
a = 10;
b = 20;
}
Overloading(int a , int b)
{
this.a = a;
this.b = b;
}
Overloading(int x )
{
a = x;
b = 20;
}
}
class Test
{
public static void main( String args[] )
{
Overloading o1 = new Overloading();
Overloading o2 = new Overloading(30,40);
Overloading o3 = new Overloading(50);
System.out.println("First Object o1: A: "+o1.a+" B: "+o1.b );
System.out.println("Second Object o2: A: "+o2.a+" B: "+o2.b );
System.out.println("Third Object o3: A: "+o3.a+" B: "+o3.b );
}
}
{
int a , b ;
Overloading()
{
a = 10;
b = 20;
}
Overloading(int a , int b)
{
this.a = a;
this.b = b;
}
Overloading(int x )
{
a = x;
b = 20;
}
}
class Test
{
public static void main( String args[] )
{
Overloading o1 = new Overloading();
Overloading o2 = new Overloading(30,40);
Overloading o3 = new Overloading(50);
System.out.println("First Object o1: A: "+o1.a+" B: "+o1.b );
System.out.println("Second Object o2: A: "+o2.a+" B: "+o2.b );
System.out.println("Third Object o3: A: "+o3.a+" B: "+o3.b );
}
}
Output: