Creating and Utilizing an Object to Display Greeting

Report a typo

Given a portion of a Java program where a class 'HelloObject' is defined. This class has a constructor and a method 'sayHello'. The class also has a 'main' method where an instance of 'HelloObject' is created and 'sayHello' method is called. The 'main' method should print 'Hello, World!'. Your task is to complete this Java program by filling the blanks in the code to make it perform the described functionality.

Fill in the gaps with the relevant elements
public class  {
    String greeting;

    public HelloObject(String greeting) {
        .greeting = greeting;
    }

    public String sayHello() {
        return this.greeting;
    }

    public static void main(String[] args) {
        HelloObject myObject =  HelloObject("Hello, World!");
        System.out.println(myObject.sayHello());
    }
}
thisnewHelloObject
___

Create a free account to access the full topic