A good answer might be:It would be nice if different objects printed different things. |
Methods can use VariablesIf different instances (different objects) of the HelloObject class are to print different things, then each instance will have its own unique data, which will have to be initialized. This calls for a constructor. Here is what a class definition usually looks like:
Important: An object's methods use the object's variables (the data of the object.) 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 often use those variables. |
QUESTION 14:If each instance of HelloObject had its own message, where would that message be kept? Click Here after you have answered the question |