Java Reference
In-Depth Information
13. Save the source file, then recompile and run the modified program in the
command window:
➔
javac HelloWorld.java
➔
java HelloWorld
Your output window should look like this:
Hello World!
Some Text
Some Text
msgSize 9
interface G
counter 3
Some New Text
Some Text for #2
Some New Text
SOME NEW TEXT
msgSize
,
interface
, and
counter
are now printed in the output window.
14. As another experiment, you'll adjust HelloWorld so that it prints out the
data members after it calls the overloaded
getErrorMsg
method (that is, the
one that accepts a parameter). Add the
bolded
lines of code to the end of
the
HelloWorld
class so that it looks like this:
// Call the new variation on getErrorMsg.
tempMsg = myErrorMsg.getErrorMsg ('U');
System.out.println (tempMsg);
// Print the public variables after performing this overloaded call.
System.out.println ("msgSize " + myErrorMsg.msgSize);
System.out.println ("interface " + myErrorMsg.interfaceInUse);
System.out.println ("counter " + myErrorMsg.getCounter ());
15. Save the source file, then recompile and run the modified program in the
command window:
➔
javac HelloWorld.java
➔
java HelloWorld
Your output window should look like this: