Creating a static message in a class

Report a typo

Suppose you have created a class in Java and you want to have a message that can be accessed without instantiating this class. Also, you want this message to be unchanged in different instances of the class. Fill the blanks in code to create such a class with a 'getStaticMessage' method that returns this message and a main method to print this returned message.

Fill in the gaps with the relevant elements
 class MyStaticClass {
       String MESSAGE = "Hello, world!";
    
    public MyStaticClass() {
    }

    public static String getStaticMessage() {
        return MESSAGE;
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println(MyStaticClass.getStaticMessage());
    }
}
finalprivatepublicstatic
___

Create a free account to access the full topic