Java Reference
In-Depth Information
2. Save this class definition as a text file, then compile the class in the DOS
command window:
javac TextMessage.java
3. Edit the ErrorMsg class with the text editor. You will define it as a class that
inherits from TextMessage and delete some class variables. Add the bolded
code, and remove the italicized code in the beginning of the file, as identi-
fied here:
public class ErrorMsg extends TextMessage {
// Define some public class instance variables.
public String msgText;
public int msgSize;
// Define some private class instance variables.
private int counter = 0;
char interfaceInUse;
// Define a public method.
public void setErrorMsg (String inputMsg) {
// Define a local variable and increment it.
int localCounter = 0;
localCounter = localCounter + 1;
// Modify some of the private variables.
counter = counter + 1;
interfaceInUse = 'S';
// Modify one of the public variables. Set this variable to the text
// String that was passed as a parameter.
msgText = inputMsg;
// Set this variable to the length of the text String.
msgSize = msgText.length ();
setMsgText (inputMsg);
...
4. Save this class definition as a text file, then compile the class in the DOS
command window:
javac ErrorMsg.java
5. Let's simplify the HelloWorld application and add a call to this new
method using the text editor. Open the HelloWorld.java source file and re-
move the lines after this statement (but remember to leave in the two curly
braces at the end of the program):
Search WWH ::




Custom Search