Java Reference
In-Depth Information
E
RROR
M
SG
C
LASS
This portion of the
ErrorMsg
class increments the private variable named counter.
public class ErrorMsg {
public String msgText;
public int msgSize;
private int counter = 0;
package char interfaceInUse;
public void setErrorMsg (String inputMsg) {
counter = counter + 1;
interfaceInUse = 'S';
...
// Some logic
...
}
}
You can examine the new member definitions and how they are used:
This example also introduces the concept of data variable initialization. Simi-
lar to COBOL's syntax, Java variables can be assigned an initial value. Unless a spe-
cific value is given, variables are initialized with their default natural values (for
example, NULL for object types, and 0 for numeric types). The developer can assign
other initial values to variables using the syntax
= value
or by using the
new
direc-
tive for objects.