Java Reference
In-Depth Information
C ALLER C LASS
This statement could be read as follows: “Create a new object of class ErrorMsg ,
and give it the name myErrorMsg .”
This statement allocates memory for the new object, calls its constructor (more
on this later), and returns a reference variable (a kind of pointer) to this new object.
In the example, the pointer to the new class is stored in the object reference variable
myErrorMsg . This reference variable is managed by the calling program in a manner
very similar to the way MYSUBx-CONTROL areas are managed in the COBOL pro-
gram. Note that the class name and the constructor name are the same and that the
constructor is called with an empty parameter list, indicating the default constructor.
Later, the program that contains this statement can use the reference variable
name myErrorMsg to refer to any class data members that belong to this object. The
period (.) operator is used to access members of an object. The member name is
used to specify which member is being accessed.
For example, statement 1 will assign a string containing "Some Text" to the
member variable msgText . The object that is modified is “pointed to” by the refer-
ence variable myErrorMsg .
 
Search WWH ::




Custom Search