Source of GreetingR.java


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