Java Reference
In-Depth Information
// Experiment with Java statements.
String testMsg = myErrorMsg.getErrorMsg ();
if (myErrorMsg.getErrorMsg ().equals (testMsg)) {
// Define a temporary integer variable.
int i = 5;
System.out.println ("testMsg = text in ErrorMsg");
System.out.println ("i = " + i);
}
else {
System.out.println ("i = " + i);
}
System.out.println (“i = “ + i);
Attempt to compile this class. You should get an error message indicating
that the compiler does not know the definition of the variable i . Delete the
first println statement, then the other statement. Is either valid? What does
this tell you about the scope of local variable i ? Can it be accessed outside
the code block where it was created (as defined by a pair of matching braces
{})? Where would you need to place the definition of i in order to compile
the previous Java statements? Go ahead and try it.
The code samples presented till now have all used the // style of com-
ment identification. You will experiment with other styles of comment
identification.
3. Comment out the lines you just added:
// Experiment with Java statements.
String testMsg = myErrorMsg.getErrorMsg ();
if (myErrorMsg.getErrorMsg ().equals (testMsg)) {
// Define a temporary integer variable.
int i = 5;
System.out.println ("testMsg = text in ErrorMsg");
System.out.println ("i = " + i);
}
/* Comment out the next few lines.
else {
System.out.println ("i = " + i);
}
System.out.println ("i = " + i);
Comment out the next few lines. */
Recompile this program.
Search WWH ::




Custom Search