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

Answer:

See below.

Remember that the super reference must be in the first statement of the constructor.


New toString()

Here are the class definitions 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;
  
  // constructor
  public MusicVideo ( String ttl, int len, String art, String cat )
  {
    super( ttl, len );
    artist   = art;
    category = cat;
  }

  // The toString() method goes here
  
}

To finish the MusicVideo class, write a toString() method for it. Use a super reference to do the things already done by the parent class.


QUESTION 23:

Write the toString() method.


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