Java Reference
In-Depth Information
// The standard constructor for a class
// It is passed no parameters.
ErrorMsg () {
total_counter = -1;
}
// A constructor for this same class that is passed one parameter
// It will call the standard constructor (to initialize the counter member).
ErrorMsg (String initialMsgText) {
this.ErrorMsg // Perform the standard constructor
msgText = initialMsgText;
}
E XERCISES : C LASS M EMBERS
It's time to revisit the example classes and try out all these new ideas.
1. Using a text editor, edit the Java source file ErrorMsg.java in the java4cobol
directory. You will add some additional variables to it and examine how a
calling program can access these variables. Add the bolded lines of code to
the beginning of the file so that it looks like this:
public class ErrorMsg {
// 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) {
// Modify some of the private variables.
counter = counter + 1;
interfaceInUse = 'S';
// Modify one of the public variables. Set this variable to the text
// String parameter.
msgText = inputMsg;
// Set this variable to the length of the text String.
msgSize = msgText.length ();
Search WWH ::




Custom Search