Java Reference
In-Depth Information
// Define a method to return localCounter.
public int getLocalCounter () {
int localCounter = 0;
localCounter = localCounter + 1;
// Return from this method with the value of localCounter.
return (localCounter);
}
18. Save this class, and then compile it in the command window:
javac ErrorMsg.java
19. 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 ());
// Print the localCounter variable.
System.out.println
("localCounter " + myErrorMsg.getLocalCounter ());
20. Save the source file, then recompile and run the modified program in the
command window:
➔ javac HelloWorld.java
➔ java HelloWorld
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
Search WWH ::




Custom Search