Java Reference
In-Depth Information
8.
Specify a getName method header so that the method is:
A.
Public
Returns a
String
variable
B.
C.
Accepts nothing
9.
In the getName method body, enter the following statement:
return
empName;
The keyword
return
actually passes the variable (specified after the
return
keyword) to the class that invokes the
getName method. In this case, the variable empName will be sent back.
10.
Change the constructor so that the setName method is invoked to assign the value to
empName.
11.
Format and save the Employee source code and verify there are no errors.
The executable statements should look like the following:
package
c3;
public class
Employee {
private
String empName = new String();
public
Employee(String name) {
this
.setName(name);
}
public void
setName(String name) {
empName = name;
}
public
String getName() {
return
empName;
}
}
12.
Run EmployeeApp.
The EmpFrame should be displayed as in Figure
3-12
.