Home Segments Top Top Previous Next

529: Sidetrip

Instances of a reference type cannot be stored so straightforwardly, because the number of bytes required for each element may vary.

For example, an instance of the Attraction class will need fewer bytes than will instances of the Movie and Symphony classes, both of which are subclasses of the Attraction class. Yet instances of the Movie and Symphony classes are valid occupants of an Attraction array.

Accordingly, you cannot store mixtures of Attraction, Movie, and Symphony instances consecutively, expecting that the nth element will be offset from the beginning of the array by n times a fixed number of bytes.