Computer Science, asked by Prisilla, 7 months ago

Write a program to demonstrate the usage of Constructor Overloading.



Answers

Answered by anindyaadhikari13
5

\star\:\:\:\sf\large\underline\blue{Question:-}

  • Write a program to demonstrate the use of Constructor overloading.

\star\:\:\:\sf\large\underline\blue{Example\:Program:-}

class Constructor

{

Constructor()

{

System.out.println("This is default constructor.");

}

Constructor(int n)

{

System.out.println("This is parameterised constructor.");

System.out.println("Number you entered: "+n);

}

Constructor(int x, int y)

{

System.out.println("This is another parameterised constructor.");

System.out.println("Product of the two numbers: "+(x*y));

}

}

public class XYZ

{

public static void main(String s[])

{

Constructor obj1=new Constructor();

Constructor obj2=new Constructor(5);

Constructor obj3=new Constructor(5,10);

}

}

Similar questions