Java Reference
In-Depth Information
E RROR M SG C LASS : S TATIC V ARIABLE
The ErrorMsg class is enhanced to define a static variable, and a default static
method to initialize that variable.
public class ErrorMsg {
public String msgText;
public int msgSize;
private int counter = 0;
char interfaceInUse;
public static int total_counter;
public final static int NO_TEXT_FOUND = 0;
// A static initializer method with no name and no parameters
static {
total_counter = 0;
}
// A public method with no parameters:
public void setErrorMsg () {
}
// A public method with the same name and one parameter of type String.
// This is actually a different method, or interface definition.
public void setErrorMsg (String inputMsg) {
interfaceInUse = 'S';
msgText = inputMsg;
msgSize = msgText.length ();
// Call the manageCounters method.
manageCounters ();
}
// A package method named manageCounters.
// This method is only visible to other classes in this package.
void manageCounters () {
counter = counter + 1;
total_counter = total_counter + 1;
}
}
E RROR M SG C LASS : S TATIC I NITIALIZER
Classes can also define specialized static initializer code. Like a class variable, this
block of code will be executed when the first instance of the class is initiated by a
runtime. Often this code will perform special initialization logic for the static class
Search WWH ::




Custom Search