Home Segments Top Top Previous Next

350: Mainline

To ensure that a rating method honoring your design decisions is defined in the Movie class, you perform steps that run parallel to the steps layed out in Segment 331:

First, you define an interface called, say, RatingInterface, substituting the interface keyword for the class keyword that you would expect in a class definition:

         *-- Keyword 
         | 
         v 
public interface RatingInterface { 
 ... 
} 

Second, you define the rating method in the body of the interface, as though you were defining that rating method in an abstract class, marking that method with the abstract keyword, and inserting a semicolon where you would ordinarily expect the definition's body.

         *-- Keyword 
         |                    *-- No body 
         v                    v 
public abstract int rating () ; 

Third, you define the Movie and Symphony classes to implement the RatingInterface interface, using the implements keyword, as well as to extend an appropriate superclass:

               *------------------------*-- Keywords 
               |                        | 
               v                        v 
public class Movie extends Attraction implements RatingInterface { 
 ... 
}