Home Segments Top Top Previous Next

568: Mainline

Having stored Movie instances in a vector, you might think that you could calculate the rating of one of those instances, using the rating method, as follows:

  *-- Vector access                   | 
  |                  *-- Method call  | BUG!  
  v                  v                | Object instance has 
---------------- --------             | no rating method 
v.firstElement().rating()             | 

The reason such an expression does not work is that the elements of a vector always appear to be instances of the Object class, and no rating method is defined for the Object class.