Jaws, 120 min. available: true Star Wars, 90 min. available: true
The Video class has basic information in it,
and could be used for documentaries and instructional videos.
But more information is needed for movie videos.
Let us make a class that is similar to Video,
but now includes the name of the director and a rating.
class Video
{
String title; // name of the item
int length; // number of minutes
boolean avail; // is the video in the store?
... // as above
}
class Movie extends Video
{
String director; // name of the director
String rating; // G, PG, R, or X
// constructor
public Movie( String ttl, int lngth, String dir, String rtng )
{
super( ttl, lngth ); // use the super class's constructor
director = dir; rating = rtng; // initialize what's new to Movie
}
}
The class Movie is a subclass of Video.
An object of type Movie has the following members in it:
|
|
Both classes are defined: the Video class can be used
to construct objects of that type, and now the Movie class
can be used to construct objects of the Movie type.
Does a child class inherit both variables and methods?