With a rating
method installed in the Movie
class and the
Symphony
class, both of which implement the RatingInterface
interface, you can use the rating
method with either a Movie
instance or Symphony
instance assigned to a RatingInterface
variable; the rating is computed by the methods defined in the Movie
or Symphony
class:
public class Demonstrate { public static void main (String argv[]) { // Movie instance assigned to x: RatingInterface x = new Movie (5, 7, 7); System.out.println("The movie's rating is " + x.rating()); // Symphony instance assigned to x: x = new Symphony (7, 5, 5); System.out.println("The symphony's rating is " + x.rating()); } }