Java Reference
In-Depth Information
// Print the contents of ErrorMsg's String data member directly.
System.out.println (myErrorMsg.msgText);
2. Add these Java expressions at the end of the previous statement (before the
last two curly braces):
// Experiment with Java statements.
String testMsg
myErrorMsg.getErrorMsg ()
3. Save these modifications as a text file, and then compile the class in the
DOS command window:
javac HelloWorld.java
You should get an error message indicating that a semicolon is missing.
Add a semicolon to the end of each of these expressions. Compile this class
again. It should now compile successfully.
4. These two statements simply define a String variable, and execute the
getErrorMsg() method in the ErrorMsg class. As written, they are not very
useful, since you end up with an empty String variable, and the result of
this effort is lost. Add this additional bolded Java code to the statements,
making them more useful:
// Experiment with Java statements.
String testMsg;
testMsg = myErrorMsg.getErrorMsg ();
Compile this class again.
5. Combine these two statements into one, as follows:
// Experiment with Java statements.
String testMsg = myErrorMsg.getErrorMsg ();
Compile this class again.
6. Next, you'll adjust the original statement and make it more complex. Al-
though you are using the if statement in this code (and I won't explore it
in detail until the next chapter), you should be able to follow it fairly eas-
ily. Add this additional bolded Java code:
Search WWH ::




Custom Search