Java Reference
In-Depth Information
Notice that we didn't fully identify the getEmpName method as this.getEmpName . Remember that the JVM
assumes that a called method is for this object.
5.
Save the Employee source code and run EmployeeApp.
6.
Close EmployeeFrame by clicking on the Exit button.
In the console pane, notice that the memory location for emp is no longer displayed. Instead, the emp value
appears as follows:
emp value after the object is assigned: Mary Worker
7. Display the UsefulFrame source code, click Source , then Override/Implement Methods... .
Look at all the inherited methods! (The Oracle online class documentation also lists all inherited methods.)
8.
Scroll down the list and expand Component.
Even more inherited methods!
9.
Scroll down the list until toString appears, select it, and click the OK button.
10.
Change the toString stub to display the frame title followed by the word “Frame” as follows:
return this .getTitle() + " Frame";
This time we fully qualified the getTitle method with the keyword this (even though we did not have to). Notice
also how concatenation was used inside the return statement to build the returned string value.
11.
Save the source code and run EmployeeApp.
12.
Close EmployeeFrame by clicking on the Exit button.
In the console pane, the value of ef should appear as follows:
The value of ef is Employee Information Frame
In case you haven't guessed, the String class also overrides the toString method it inherited from Object. String.
toString() returns the text value assigned to the String object, not the memory location. So using println to display
String variables will display the assigned text (as you would hope), not the memory location. Wasn't this nice of the
Java developers?
13.
In EmployeeApp, comment out all the println statements and the statements defining
intTest and doubleTest.
The executable code should look like the following:
package c5;
public class EmployeeApp {
public static void main(String[] args) {
Employee emp = null ;
emp = new Employee("Mary Worker", "1 Main St.",
"Enid", "OK", "77777");
EmployeeFrame ef = new EmployeeFrame(emp);
}
}
Search WWH ::




Custom Search