Java Reference
In-Depth Information
public class ErrorMsg {
public String msgText;
public int msgSize;
(1) public void setErrorMsg (String inputMsg) {
...
// Some logic
...
// The method is complete. Return to the caller.
return;
}
(2) public String getErrorMsg () {
...
// Some logic
...
// The method is complete.
// Return a String variable as the result (or return argument) of this
// method.
return (returnMsg);
}
(3) public String getErrorMsg (int msgCode) {
...
// Some logic
...
return (returnMsg);
}
}
The new message definition statements (2 and 3) could be read this way: “De-
fine a public method for class ErrorMsg . This method returns a String data item, and
the method's name is getErrorMsg . One form of this method accepts no parameters
(statement 2), and another form accepts one parameter of type int (statement 3).”
The method getErrorMsg defines other functions that ErrorMsg can support. As
such, these are additional components of the interface to ErrorMsg . These methods
can access any of ErrorMsg 's data items or methods (both public and private ones).
Since the methods are themselves public, any class can call these methods.
Notice that the methods named getErrorMsg have different signatures (inter-
face definitions) than the setErrorMsg method. They do not have a String input pa-
rameter, but they do return a String variable.
Search WWH ::




Custom Search