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

Answer:

The finished class is given below.


Complete MusicVideo Class

The toString() method for MusicVideo uses super.toString(). It does not have to be the first statement.

class Video
{
  // stuff omitted
  . . .
  
  public void toString()
  {
    return title + ", " + length + " min. available:" + avail ;
  }
  
  . . .
  
}

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;
  }
  
  public String toString()
  {
    return super.toString() +  "artist:" + artist + " style: " + category ;
  }
  
  // Setters and Getters
  public String  getArtist() { return artist; }
  public String  getCategory() { return category; }
}

QUESTION 24:

Would the following toString() method work in MusicVideo ?

public String toString()
{
  return  title + length + " min. available:" + avail + "\nartist:" + artist + " style: " + category ;
}

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