You are on page 1of 1

20) Write a program to show the use of constructor

overloading

class Test{

//default constructor
Test()
{
System.out.println("this is default constructor");
}
Test(int a)
{
System.out.println("single parameter constructor :"+a);
}

Test(int a,int b)
{
System.out.println("two parameter constructor");
}

class onstructorOverloading{

Test t;
t=new Test(); // call default constructor
t= new Test(10); // class single parameter
t= new Test(10,20)//two parameter

output
thia is default onstructor
single parameter constructor:10
two parameter conatructor

You might also like