Answer to Question #239744 in Java | JSP | JSF for zakia kafeel

Question #239744

Create a Java program that simply outputs the text "Hello World" when you run it. Call your main class

"Application". In the same file as your main "Application" class, define a new class called "Person". You

don't need to put anything in the class. Now, right below where you output "Hello World" in your main

method, create an object from that (Person) class. Modify your "Person" class to add a constructor.

Make the constructor output the text "Constructor running!". Add another constructor in addition to

the constructor it's already got. Make this second constructor accept a parameter called name of type

String. Make this second constructor print the name parameter using System.out.println(). Finally,

change your "main" method, create two objects of Person class and call both constructors.


1
Expert's answer
2021-09-21T04:03:53-0400
class Person {
    public Person() {
        System.out.println("Constructor running!");
    }
    
    public Person(String name) {
        System.out.println(name);
    }
}


public class Main {


    public static void main(String[] args) {
        
            System.out.println("Hello World!");
            Person person = new Person();
            Person person2 = new Person("Bob");
    }


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS