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.
Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClasses and objectsClasses and members
Instance methods
Implementing an instance method to print greeting messages
Report a typo
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);
}
} ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.