Java Reference
In-Depth Information
A. When you invoke/run EmployeeApp as an application, the computer “knows” to load the statements in
EmployeeApp's main method into main memory and execute them. The square in Figure 2-4 represents the main
method in main memory.
Figure 2-4.
The EmployeeApp statement is considered an assignment statement and is doing quite a bit of work. It creates
two objects (one String and one Employee) and an Employee variable. It assigns the Employee object to the variable
and passes the String object to Employee. Wow! We better look a little closer at each piece of the statement and
explain what each does.
First of all, in an assignment statement everything to the right of the equal sign is executed first. Then everything
on the left side of the equal sign is executed and lastly the assignment is done. If there are multiple functions within
a statement, any statements in parentheses are executed first and then they are executed from right to left. So in
this example:
B. The code new String("Joe Employee") is executed first because it is on the right side of the equal sign and in
parentheses. The code creates a new String object (represented by the first rounded corner rectangle in Figure 2-4 )
with the text “Joe Employee”.
C. Then the code new Employee() is executed. This creates a new Employee object (represented by the second
rounded corner rectangle in Figure 2-5 ). When an object is created all the executable code from the class is loaded
into main memory, the class variable statements are executed, and if there are values being passed to the new object,
they are given to the constructor and the constructor is executed.
 
Search WWH ::




Custom Search