Write a program to demonstrate the usage of Constructor Overloading.
Answers
Answered by
5
- Write a program to demonstrate the use of Constructor overloading.
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