Java Reference
In-Depth Information
Your applet window should look like this:
Hello applet World!
Some Text
Some New Text
Some Text for #2
Some New Text
SOME NEW TEXT
R EVIEWING THE S AMPLES
Let's review the class you've created ( ErrorMsg ) and the main program that uses it
(HelloWorld). Try to relate the sample source statements to the result (for exam-
ple, the output) each statement creates. If necessary, rerun the samples or look at
the complete source code at the end of this section. Feel free to experiment by
yourself.
ErrorMsg is the first example of a reusable class. Your first program, Hello-
World, was a standalone application . ErrorMsg , on the other hand, is a class that
HelloWorld can use. The original HelloWorld program from the first set of ex-
ercises was modified to use this class.
HelloWorld first creates a new instance of ErrorMsg with this statement:
ErrorMsg myErrorMsg = new ErrorMsg ();
To confirm that an instance has been created, HelloWorld prints out the con-
tents of one of ErrorMsg 's public data members. The default value for a String
data type is null . The ErrorMsg class as defined in the example in the first path
of this chapter does not specify any initial data. Therefore, these statements
System.out.println ("HelloWorld!");
tempMsg = myErrorMsg.getErrorMsg ();
System.out.println (tempMsg);
Search WWH ::




Custom Search