Of course. The class definition for HelloObject
works like a cookie cutter.
We can cut out as many cookies as we want.
Here is an expanded program that creates several HelloObject
s
(and several String
objects.)
class HelloObject { String greeting; HelloObject( String st ) { greeting = st; } void speak() { System.out.println( greeting ); } } class HelloTester { public static void main ( String[] args ) { HelloObject object1 = new HelloObject("Mercury"); HelloObject object2 = new HelloObject("Venus"); HelloObject object3 = new HelloObject("Earth"); HelloObject object4 = new HelloObject("Mars"); object1.speak(); object2.speak(); object3.speak(); object4.speak(); } }
The program writes this to the monitor:
Mercury Venus Earth Mars
What names may be used for parameters?