Home Segments Top Top Previous Next

195: Mainline

Note the contrast between the definition of a rating instance method and that of a rating class method:

      *-- No static keyword in instance method 
      |            *-- Instance method needs 
      |            |   no instance argument 
      v            v  
public int rating ( ) { 
 return script + acting + direction; 
}      ^       ^        ^ 
       *-------*--------*-- Instance method assumes that instance  
                            variables are those of the target instance 

         *-- The static keyword appears in class method 
         |                  *-- Class method needs 
         |                  |   instance argument 
         v                  v 
       ------             -------   
public static int rating (Movie m) { 
 return m.script + m.acting + m.direction; 
}       ^          ^          ^ 
        *----------*----------*-- Class method needs to reference 
                                  instance variables using the 
                                  field-selection operator