In the example program, the class definition for Video
includes a constructor, so the default constructor
was not automatically supplied.
So the constructor proposed for Movie
causes a syntax error.
Let us not use it.
Movie
Here is version of main()
that makes use of the two classes:
public class VideoStore { public static void main ( String args[] ) { Video item1 = new Video("Microcosmos", 90 ); Movie item2 = new Movie("Jaws", 120, "Spielberg", "PG" ); System.out.println( item1.toString() ); System.out.println( item2.toString() ); } }
The program prints:
Microcosmos, 90 min. available:true Jaws, 120 min. available:true
The statement item2.toString()
calls the toString()
method
of item2
.
This method was inherited without change from the class
Video
.
This is what it looks like:
public String toString() { title + ", " + length + " min. available:" + avail ; }
It does not use the new variables that have been added to Movie
objects
so the director and rating are not printed out.
Why not change toString()
in Video
to this:
public String toString() { title + ", " + length + " min. available:" + avail + "dir: " + director + ", rating: " + rating ); }