Java Reference
In-Depth Information
Figure 2-12.
So, the result of running EmployeeApp is three objects and three variables. Of course, there is no visible evidence
of any of this activity. We need to change EmployeeApp to invoke the Employee method displayName. To invoke
an object method, specify the variable name (emp) that the object is assigned to, followed by a period, the method
name, parentheses and a semicolon (i.e., emp.displayName();) . Notice that the variable name, not the class name is
specified. In this example, this means you are specifying emp not Employee. If the method being called required data,
that data would be specified within the parentheses.
3.
Replace the println statement in EmployeeApp with the following:
emp.displayName();
The executable code should look like the following:
package myFirstPackage;
public class EmployeeApp {
public static void main(String[] args) {
Employee emp = new Employee( new String("Joe Employee"));
emp.displayName();
}
}
 
Search WWH ::




Custom Search