Home Segments Top Top Previous Next

340: Mainline

Note that, should you declare a variable to be an Attraction variable, assigned to a Movie instance, you can call only the ordinary or abstract methods that appear in the Attraction class. Thus, even if both the Movie class and the Symphony class define, say, a method named profit, the following will not compile:

public class Demonstrate { 
 public static void main (String argv[]) { 
  // Movie instance assigned to x: 
  Attraction x = new Movie (7, 7, 7); 
  System.out.println("The movie's profit is " + x.profit()); 
  // Symphony instance assigned to x: 
  x = new Symphony (7, 7, 7); 
  System.out.println("The symphony's profit is " + x.profit()); 
 } 
}