Java Reference
In-Depth Information
The ErrorMsg class has two methods defined for it: setErrorMsg and getEr-
rorMsg . You can define a variation on getErrorMsg . This alternative, or overloaded
method, will convert the returned String to all uppercase letters.
1. Using a text editor, edit the Java source file ErrorMsg.java in the java4cobol
directory.
2. Add the following lines to the end of your ErrorMsg.java source file (i.e.,
immediately before the last brace (}) in the class):
// Define a variation on the public method getErrorMsg.
public String getErrorMsg (char caseFlag) {
String returnMsg;
// Set the local variable returnMsg to the data member msgText.
returnMsg = msgText;
// Convert to all uppercase, if requested.
if (caseFlag == 'U')
returnMsg = returnMsg.toUpperCase ();
// Return from this method, and return the String variable.
return (returnMsg);
}
3. Compile the class again in the DOS command window:
javac ErrorMsg.java
4. Modify HelloWorld to use this new method. Using a text editor, edit the
Java source file HelloWorld.java in the java4cobol directory.
5. Add the following lines to the end of your HelloWorld.java source file (i.e.,
immediately after the last println statement):
// Call the new variation of the getErrorMsg method.
// This variation will return an all uppercase message.
tempMsg = myErrorMsg.getErrorMsg ('U');
System.out.println (tempMsg);
6. Compile and execute the program again in the DOS command window:
javac HelloWorld.java
java HelloWorld
Search WWH ::




Custom Search