Using a Super Class's Constructor

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

Yes — the method show in the superclass Video is inherited in the subclass Movie.

Using a Super Class's Constructor

The class definition for Video has a constructor that initializes the member data of Video objects. The class Movie has a constructor that initializes the data of Movie objects. The constructor for class Movie looks like this:

// constructor
public Movie( String ttl, int lngth, String dir, String rtng )
{
  super(ttl, lngth);               // use the super class's constuctor
  director = dir;  rating = rtng;  // initialize the members new to Movie
}

The statement super(ttl, lngth) invokes a constructor of the parent to initialize some of the data. There are two constructors in the parent. The one that is invoked is the one that matches the argument list in super(ttl, lngth). Then the next two statements initialize the members that only Movie has.

Note: super() must be the first statement in the subclass's constructor.

QUESTION 11:

Why is the statement that invokes the parent's constructor called super()?