public class Greeting
1: //Greeting.java
2:
3: public class Greeting
4: {
5: private String text;
6:
7: public Greeting()
8: {
9: text = "Nothing to say";
10: }
11:
12: public Greeting
13: (
14: String newText //in
15: )
16: {
17: text = newText;
18: }
19:
20: public String getText()
21: {
22: return text;
23: }
24:
25: public void setText
26: (
27: String newText //in
28: )
29: {
30: text = newText;
31: }
32:
33: public static void main(String[] args)
34: {
35: Greeting myGreeting = new Greeting();
36: System.out.println(myGreeting.getText());
37: Greeting yourGreeting = new Greeting("Hello");
38: System.out.println(yourGreeting.getText());
39: myGreeting.setText("Hi there!");
40: System.out.println(myGreeting.getText());
41: }
42: }
43: