Java Reference
In-Depth Information
13.
Run EmployeeApp again.
RAD will display the “Save and Launch” window listing both classes because they both have unsaved changes.
14.
Click the OK button to save the changes and run EmployeeApp.
Notice that the classes no longer have errors and the employee name is correctly displayed in the console pane.
Tutorial: Breaking the Code, Parameters, and Signatures
Let's begin:
On line 9 in EmployeeApp, remove the text “ new String("Mary Worker") ” so that the
statement looks like the following:
1.
Employee emp = new Employee();
Notice that RAD flags the line as an error and puts a red squiggle under new Employee() .
2.
Move your cursor over the red squiggle.
The message “The constructor Employee( ) is undefined” is displayed. This brings up an interesting point.
We mentioned earlier that a method has a name (for instance, Employee). However, the name does not fully identify
a method. A method is fully identified by its signature . A method signature is comprised of both the method name
and the parameters the method is expecting. In our example, we defined a method called Employee that expects one
string as a parameter. With the change, we no longer specify a string, therefore, the computer tries to run a constructor
method called Employee that expects no parameters. Because Employee does not have a method with this signature,
an error is generated.
Put the text “ new String("Mary Worker") ” back in the statement on line 9.
3.
In Employee on line 9, add the text “ new String("Frank") ” so that the statement looks like
the following:
4.
this.displayName( new String("Frank"));
Notice that again, RAD indicates there is an error.
5.
Move the mouse cursor over the red squiggly line to display the following message:
“The method displayName( ) in the type Employee is not applicable for the arguments (String)”
Sometimes RAD's messages leave something to be desired.
Unfortunately, in Java-speak, parameters can be referred to as arguments and classes can be referred to as types
(i.e., as in class type). So this message is inferring (in its own way) that there is no method with the correct signature.
Remember, the correct parameters must be passed to a method; otherwise, the statement will result in an error.
We will explore parameter passing in more detail in future chapters.
Click Edit then Undo until the text is removed.
6.
7.
Save the source code for both EmployeeApp and Employee.
Although we have criticized RAD a little for its messages, you should drop to your knees and thank RAD for how
easy it is to run applications. Here's why.
 
Search WWH ::




Custom Search