Computer Science, asked by arohi4, 1 year ago

program for overloading constructor? plz explain & write quickly.

Answers

Answered by siddhartharao77
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);    
  }
}

arohi4: what it's output
arohi4: plz reply me bro
siddhartharao77: Welcome to the java I am A weapon My name is John cena and I weigh 396
arohi4: Ooo
arohi4: tq
Similar questions