// file: GreeterTest.java // CH program shows a method (sayHello) that returns a String object // The Greeter class has no instance variables and a "default" constructor /** * A class to print a greeting */ class Greeter { /** * Prints the String "Hello, World!" **/ public String sayHello() { String message = "Hello, World!" ; // "message" is a local variable return message ; } } /** * A test class for the Greeter class */ public class GreeterTest { public static void main(String[] args) { Greeter worldGreeter = new Greeter() ; // print the String returned by the sayHello method System.out.println( worldGreeter.sayHello() ) ; } } /* Program output: Hello, World! */