A good answer might be:Because the class VideoTape, does not have the variables director nor rating, so its show() method can't use them. | ||
Overriding MethodsWe need a new show() method in the class Movie:
Now, even though the parent has a show() method the new definition of show() in the child class will override the parent's version. A child overrides a method from its parent by defining a replacement method with the same signature. Now the parent has its method, and the child has its own method with the same name. With the change in the class Movie the following program will print out the full information for both items.
The line item1.show() calls the show() method defined in VideoTape, and the line item2.show() calls the show() method defined in Movie. Microcosmos, 90 min. available:true Jaws, 120 min. available:true dir: Spielberg PG | ||
QUESTION 12:Does the definition of show() in the Movie class include some code that is already written? Click Here after you have answered the question |