Java Reference
In-Depth Information
Now look at the following statements and determine if they compile and what their result is:
45. Customer y = new Customer(101, “Dr. Watson”);
46. System.out.println(y.getName());
47. Customer z = new Customer(202, “Mr. Rattigan”);
48. z.processOrder(“Widget #4”);
49. System.out.println(z.getName());
The code compiles fi ne. Two Customer objects are instantiated in memory, as shown in
Figure 2.10. The output of the code is
Dr. Watson
Mr. Rattigan is ordering a Widget #4
Mr. Rattigan
FIGURE 2.10 Each Customer object has its own instance fields and methods in
memory.
Customer
reference
Customer object
y
name
“Dr. Watson”
id
101
setName
getName
setld
getld
processOrder
Customer
reference
Customer object
z
name
“Mr. Rattigan”
id
202
setName
getName
setld
getld
processOrder
Search WWH ::




Custom Search