Java Reference
In-Depth Information
23. Add these Java
bolded
statements to the end of the
HelloWorld
class, but
before the
checkIntArray()
function:
// Test if any are equal to 30.
checkIntArray (errorNumbersIO);
// Set an error code to 30, and call the checkIntArray function again.
errorNumbersIO[1] = 30;
checkIntArray (errorNumbersIO);
Following are the results when you execute the program:
}
error Number 0 = 1
error Number 1 = 2
error Number 2 = 10
error Number 3 = 22
error Number 4 = 23
error Number 0 = 1
Found '30' at index 1
Since you are a very clever programmer, try out these adjustments on your own
in the HelloWorld applet. For your convenience, the completed applet sample code
is included on the CD-ROM.
R
EVIEWING THE
S
AMPLES
Let's review the changes you've made to
ErrorMsg
and
HelloWorld
. Try to relate the
sample source statements to the result (the output) each statement creates. If nec-
essary, rerun the samples or look at the complete source code for this exercise on
the CD-ROM. Feel free to experiment by yourself.
The
ErrorMsg
class was adjusted to include some private and package data
members.
HelloWorld
could access the public (
msgText
and
msgSize
) and package (
inter-
faceInUse
) data members directly but could not access the private (
counter
)
data members.
You needed to create a new method (
getCounter
) in order to access this private
data member.
You changed the second version of the method
getErrorMsg
(in
ErrorMsg
) so
that it called the first version and then performed its custom logic. Notice that