Java Reference
In-Depth Information
Save EmployeeApp, then click Run , Run As , and then Java Application .
4.
The text “Joe Employee” will be displayed in the Console pane.
5.
In EmployeeApp, change the text “Joe Employee” to “Mary Worker”.
6.
Save EmployeeApp and click the Run button (the green circle with a white arrowhead).
The text “Mary Worker” will be displayed in the console pane. This exercise has proven two things:
A. When a class is run as an application, the class's main method is run.
B. When an object is instantiated (i.e., an instance of the class is created), the class constructor method is run.
In addition, this exercise showed you how to execute/invoke a method and how to pass information to an object.
Tutorial: Breaking the Code, Public vs. Private Access
Let's break some code:
1.
Display the Employee class source code by clicking the Content pane tab for
Employee.java.
Highlight the keyword public on line 11 as seen in Figure 2-13 and type private .
2.
Figure 2-13.
3.
Save the source code.
4.
Click the Run drop down button and select EmployeeApp.
5.
At the Errors in Workspace window, continue the launch by clicking the Proceed button.
Even though you are editing Employee, RAD runs EmployeeApp because that is the launch that was selected.
The following error message will be displayed in the console:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method displayName() from the type Employee is not visible
at myFirstPackage.EmployeeApp.main(EmployeeApp.java:10)
 
Search WWH ::




Custom Search