Java examples for Object Oriented Design:Field
Proper way to declare a class variable named helloMessage:
public class HelloApp { public static void main(String[] args) { HelloSayer h =/*from www . j ava 2s.c o m*/ new HelloSayer("Hello", "World"); h.sayHello(); } } class HelloSayer { private String greeting; private String addressee; public HelloSayer(String greeting, String addressee) { this.greeting = greeting; this.addressee = addressee; } public void sayHello() { System.out.println(greeting + ", " + addressee + "!"); } }