It would be nice if different objects printed different things.
modifiers class ClassName { Description of the instance variables Description of the constructors Description of the methods }
If different instances (different objects)
of the HelloObject
class
print different strings,
then each instance must have its own data,
which must be initialized.
The class definition needs a constructor.
The instance variables are the variables that each
object (each instance of a class) has as part of itself.
Usually each instance variable is marked private
,
which means they are accessible only to the object itself.
Crude Analogy: your internal parts (your organs) are private to yourself. Your public face is what other objects (people) interact with.
An object's methods use that object's instance variables. Remember that an object has identity, state, and behavior. "Identity" means that each object has its own variables. The "state" of an object is the values held in its variables. The "behavior" of an object is its methods, which use the object's own variables.
If each instance of HelloObject
had
its own message,
where would that message be kept?