The near-complete class is below.
Here is the class with a String
reference variable included.
Of course, you may have used a different name for it.
class HelloObject { String greeting; public void speak() { System.out.println( greeting ); } }
The class is not complete because there is no way to initialize the greeting (we will get to this shortly). It would be nice if the object could be used like this:
class HelloTester { public static void main ( String[] args ) { HelloObject anObject = new HelloObject("A Greeting!"); anObject.speak(); } }
Where in the above code is a constructor being used? What is its parameter?