Java Reference
In-Depth Information
The statement could be read this way: “Define a
public
method for class
ErrorMsg
. This method returns no data (
void
) and its name is
setErrorMsg
. This
method accepts one parameter of type
String
; the parameter's name as used by the
class is
inputMsg
.”
C
ALLER
C
LASS
A consumer (calling) class can use this method in the following way:
// Create a new object of type ErrorMsg.
ErrorMsg myErrorMsg = new ErrorMsg ();
...
// Call the method in the object called setErrorMsg.
This statement calls the object's method and requests that it perform some be-
havior based on the passed parameter. Sometimes this is described as sending a
message
to that object.
M
ULTIPLE
M
ESSAGES
Classes can easily support more than one message definition or even variations on
a single message. In fact, it is this easy-to-use message specification that helps dis-
tinguish OO languages from their more procedural cousins.
C
LASS
E
RROR
M
SG
Let's look at some examples that show how a class publishes the types of messages
it can receive using Java's syntax.