Java Reference
In-Depth Information
Display this message
this.msgSize = 50, super.msgSize = 20
~~~~~~~ setErrorMsg in Diagnostic does this : ~~~~~~~
====== A serious error has occurred ======
Fri Apr 16 18:08:50 PDT 1999
Display this message
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:983)
at Diagnostic.setErrorMsg(Diagnostic.java:27)
at HelloWorld.main(HelloWorld.java:69)
====== End of serious error message =====
R EVIEWING THE S AMPLES
Let's review the changes you've made. Try to relate the sample source statements to
the result (for example, the output) each statement creates. If necessary, rerun the
samples or look at the complete source code for this exercise on the CD-ROM. Feel
free to experiment by yourself.
You first created a new class called TextMessage . You removed some of the data
members from ErrorMsg and placed them in TextMessage .
Since the data members msgText and msgSize now belong to TextMessage , you
defined a setMsgText method in TextMessage in order to set these variables.
You placed a new method named getTranslation in TextMessage . This method
examined the static variable named LANGUAGECODE.
The ErrorMsg class was adjusted to inherit from this new class. Since ErrorMsg in-
herits from TextMessage , the public members and methods in TextMessage are
automatically available to any class that creates an ErrorMsg class. In the exam-
ple, HelloWorld creates an instance of ErrorMsg and can access these variables as
if they are part of ErrorMsg . ErrorMsg and TextMessage share these variables.
When you set the static variable LANGUAGECODE to F, all instances of
TextMessage simulated a translation into French. Instances of ErrorMsg (which
are inherited from TextMessage ) also exhibit this behavior.
You created a new class PrintfileErrorMsg . It inherits from ErrorMsg .
Search WWH ::




Custom Search