Java Reference
In-Depth Information
Statement 2 is another example of how myErrorMsg.msgText can be used:
Statement 1 assigns the string "Some Text" to the data member msgText . The ob-
ject whose data member is being set is, of course, myErrorMsg . This object is an ob-
ject of type ErrorMsg . That is, it is an instance of the class ErrorMsg . Statement 2
assigns the current string in the data member msgText to a local string variable
called localText .
T ERMS TO R EVIEW : O BJECTS
Here are some object-oriented concepts and how to understand them from a Java
perspective.
Class: A Java class is a logical grouping of data and methods (methods are con-
ceptually similar to functions) that use the data. In concept, a Java class is sim-
ilar to a COBOL subroutine: It contains some data elements, it can perform
functions when requested, and the subroutine developer defines these func-
tions. Many calling programs can use this class to perform available functions
and can manage the data that belong to the class.
Object: An instance of a class. This is similar to an instance of a COBOL sub-
routine and a unique set of LINKAGE AREA items. You can think of an object
as the result of initializing the class or calling it for the first time. However, un-
like a COBOL subroutine, many instances of a class can be easily created and
managed by the same calling program.
Reference variable: A variable that contains a pointer to an object. After an ob-
ject is created, the reference variable points to it. A reference variable is used by
the calling program to access the data members and functions (that is, the
methods) that belong to the object. This is similar to an instance of CALLER's
MYSUBx-CONTROL area after the subroutine has been called.
New: The Java operation that creates an instance of the class (i.e., the object).
It returns a reference variable that points to the new object.
 
Search WWH ::




Custom Search