Home Segments Top Top Previous Next

338: Mainline

Although you cannot create an instance of an abstract class, you can declare a variable that is typed by an abstract class:

... 
Attraction x; 
... 

The value of such a variable can be either a Movie instance or a Symphony instance, because the value of a variable declared for a particular class can be an instance of any subclass:

... 
x = new Movie(); 
... 
x = new Symphony(); 
...