program for overloading constructor? plz explain & write quickly.
Answers
Answered by
1
Constructor Overloading is a technique in Java in which a class can have any number of constructors.
public class Demo
{
public Demo()
{
System.out.println("Welcome to the java");
}
public Demo(String Hello)
{
System.out.println("I am " + Hello);
}
public Demo(String Hello, int Weight)
{
System.out.println("My name is " + Hello + " and I weigh " + Weight);
}
public static void main(String args[])
{
Demo A = new Demo();
Demo B = new Demo("A weapon");
Demo C = new Demo("John cena", 396);
}
}
public class Demo
{
public Demo()
{
System.out.println("Welcome to the java");
}
public Demo(String Hello)
{
System.out.println("I am " + Hello);
}
public Demo(String Hello, int Weight)
{
System.out.println("My name is " + Hello + " and I weigh " + Weight);
}
public static void main(String args[])
{
Demo A = new Demo();
Demo B = new Demo("A weapon");
Demo C = new Demo("John cena", 396);
}
}
arohi4:
what it's output
Similar questions
Business Studies,
7 months ago
Math,
7 months ago
Math,
1 year ago
Social Sciences,
1 year ago
CBSE BOARD X,
1 year ago
Math,
1 year ago