Implementing an instance method to print greeting messages

Report a typo

Consider a simple Java program that models a Welcome object. This object holds an array of greetings and has a method which prints these greetings. You need to fill the blanks in the code to properly define this method, instantiate the class, and use this method to print an array of greetings. The array of greetings should be passed to the method as a parameter. Remember to follow best practices for implementing instance methods in classes.

Fill in the gaps with the relevant elements
 class Welcome {
    String[] greetings;  
    public  (String[] arr) {
        this.greetings = arr;
        for(String greeting : greetings) {
            System.out.println(greeting);
        }
    }  
    public static void main(String[] args) {
        Welcome myWelcome =  Welcome();
        String[] greetingsArray = {"Hello", "Hi", "Welcome"};
        myWelcome.printGreetings(greetingsArray);
    }
}
printGreetingspublicnewvoid
___

Create a free account to access the full topic