Java Reference
In-Depth Information
MYSUB COBOL: ACTION-SWITCH
If this new ACTION-SWITCH is set, MYSUB returns the value from a private variable.
01 MYSUB-CONTROL.
03 MYSUB-ACTION-SWITCH PIC X.
88 MYSUB-ACTION-EVALUATE VALUE "E".
88 MYSUB-ACTION-SET-AND-EVALUATE VALUE "S".
88 MYSUB-ACTION-GET-CALL-COUNTER VALUE "G".
03 MSG-TEXT PIC X(20).
03 MSG-SIZE PIC 9(8).
03 MYSUB-RETURNED-CALL-COUNTER S9(17) COMP-3.
...
MYSUB-INITIAL SECTION.
MYSUB-INITIAL-S.
...
*
If requested, return the value in the counter variable.
IF MYSUB-ACTION-GET-CALL-COUNTER
MOVE CALL-COUNTER TO MYSUB-RETURNED-CALL-COUNTER.
...
This type of interface would allow a calling program to ask MYSUB to return
the number of times it has been called. An approach such as this one allows the sub-
routine designer to decide which internal variables to make available and how a
calling program should access them. In support of this design, CALL-COUNTER is
managed as a private variable and MYSUB-RETURNED-CALL-COUNTER as a
public variable.
J AVA V ARIABLES
In a similar way, Java variables can be private or public. Public variables can be di-
rectly viewed or modified by other classes, whereas private variables cannot. Java
also supports package variables, which are somewhere in between (that is, they are
available to classes in a defined group of classes called a package). Variables that are
not declared private or public will default to package variables. Finally, Java also de-
fines another type, protected , which has to do with a feature called inheritance, a
topic I will discuss later.
 
Search WWH ::




Custom Search