Java Reference
In-Depth Information
26. Save and compile this class:
javac Diagnostic.java
27. Edit the HelloWorld class so that it uses this new class. Using the text edi-
tor, open the HelloWorld.java source file and add these bolded lines of
code to the bottom of the class:
// Print this data member in PrintfileErrorMsg.
System.out.println ("msgSize for PrintfileErrorMsg = " +
myErrorMsg3.msgSize);
// Experiment with polymorphism.
System.out.println ("---------- Experiment with polymorphism --------
--");
// Create an error message String, and pass it to each of these
// setErrorMsg functions.
tempMsg = "Display this message";
System.out.println ();
System.out.println ("~~~~~~~ setErrorMsg in ErrorMsg does this: ~~~~
~~~");
myErrorMsg.setErrorMsg (tempMsg);
System.out.println ();
System.out.println ("~~~~~~~ setErrorMsg in PrintfileErrorMsg does
this: ~~~~~~~");
myErrorMsg3.setErrorMsg (tempMsg);
System.out.println ();
System.out.println ("~~~~~~~ setErrorMsg in Diagnostic does this : ~~
~~~~~");
Diagnostic.setErrorMsg (tempMsg);
...
28. Save, compile, and rerun the HelloWorld application. The output should
look like this:
---------- Experiment with polymorphism ----------
~~~~~~~ setErrorMsg in ErrorMsg does this: ~~~~~~~
~~~~~~~ setErrorMsg in PrintfileErrorMsg does this: ~~~~~~~
Search WWH ::




Custom Search