go to previous page   go to home page   go to next page hear noise highlighting

Answer:

MusicVideo inherits title, length, and avail from its parent and adds artist and category.


Writing the Constructor

MusicVideo inherits only from its parent Video. It does not inherit anything from its sibling class Movie.

We need a constructor for MusicVideo. Use four parameters for title, length, artist and category. Initialize avail to true. Here is the definition so far:

class Video
{
  protected String  title;    // name of the item
  protected int     length;   // number of minutes
  protected boolean avail;    // is the video in the store?

  // constructor
  public Video( String ttl, int lngth )
  {
    title = ttl; length = lngth; avail = true; 
  }

  public void toString()
  {
    return title + ", " + length + " min. available: " + avail  ;
  }
  
  // setters and getters
   . . . 
   
}

class MusicVideo extends Video
{
  private String artist;
  private String category;

  // The constructor goes here
  
  // The toString() method goes here

}

QUESTION 22:

Write a constructor for MusicVideo. Use the super reference to the constructor in Video.


go to previous page   go to home page   go to next page