Yes.
Examine the following proposed constructor for Movie
:
// proposed constructor public Movie( String ttl, int lngth, String dir, String rtng ) { title = ttl; // do what the parent's constuctor does. length = lngth; avail = true; director = dir; rating = rtng; }
It looks like there is no need to invoke the parent class's constructor since all variables are initialized in this one. However a constructor from the parent class is always invoked even if you don't explicity ask for it. The Java compiler regards the above code as "shorthand" for this:
// proposed constructor
public Movie( String ttl, int lngth, String dir, String rtng )
{
super(); // invoke the parent's no-argument constructor
title = ttl; // do what the parent's constuctor does.
length = lngth;
avail = true;
director = dir; rating = rtng;
}
As always, super()
comes first,
even if you don't write it in.
If the parent does not have a no-argument constructor,
then using this "shorthand" causes a syntax error.
In our program the class definition for VideoTape
(the superclass) lacks a no-argument constructor.
The proposed constructor (above) calls for such a constructor
so it would cause a syntax error.