Proper way to declare a class variable named helloMessage: - Java Object Oriented Design

Java examples for Object Oriented Design:Field

Description

Proper way to declare a class variable named helloMessage:

Demo Code

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  + "!");
    }

}

Related Tutorials