![]() |
![]() |
![]() |
![]() |
![]() |
|
Note, that should you declare a variable using an interface, then you
can call only those methods that appear in that interface. 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:
RatingInterface x = new Movie (5, 7, 7);
System.out.println("The movie's profit is " + x.profit());
// Symphony instance assigned to x:
x = new Symphony (7, 5, 5);
System.out.println("The symphony's profit is " + x.profit());
}
}