Home Segments Top Top Previous Next

129: Mainline

It is important to know that the parameter values established when a method is entered are available only inside the method. It is as though Java builds an isolating fence to protect any other uses of the same parameter name outside of the method.

Consider movieRating, for example:

public class Movie { 
 // Define movieRating: 
 public static int movieRating (int s, int a, int d) { 
  return s + a + d; 
 } 
} 

When movieRating is used, any existing values for other variables that happen to be named s, a, and d are ignored:

movieRating fence-----------------*   The values of s, a, and d  
| The value of s, a, and d inside |   outside the fence, if any, 
| this fence are isolated from    |   are not affected by the 
| the values outside              |   values inside 
|                                 | 
| movieRating method computes the | 
| value of s + a + d using the    | 
| values inside this fence        | 
*---------------------------------*