Page 241 - Introduction to Programming with Java: A Problem Solving Approach
P. 241
6.5 CallingObject,thisReference 207
called method
Apago PDF FEignureh6.a7 nCcalliengra method setPercentGrowthRate, then the JVM should update jaq’s percentGrowthRate). This section
describes how the JVM knows which object to update.
Calling Object
As mentioned in Chapter 5, whenever an instance method is called, it is associated with a calling object. You can identify the calling object by looking to the left of the dot in an instance method call statement. Can you identify the calling objects in the following main method?
public static void main(String[] args)
{
}
// end main
method call
Scanner stdIn = new Scanner(System.in);
double growthRate;
Mouse gus = new Mouse();
System.out.print("Enter % growth rate: ");
growthRate = stdIn.nextDouble();
gus.setPercentGrowthRate(growthRate);
gus.grow();
gus.display();