Music Video Class

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

  1. You should not have to write the same code more than once.
  2. A change made to the method in the parent class is inherited by the child class.

Music Video Class

Music video as child of Video

So far the video rental application has two classes: Video and Movie. Say that you wanted to create a new class, MusicVideo that will be like Video but will have two new instance variables: artist (the name of the performer) and category ("R&B", "Pop", "Classical", "Other" ). Both of these will be Strings. The MusicVideo class will need its own constructor and its own show() method. Here is the parent class:



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

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

  public void show()
  {
    System.out.println( title + ", " + length + " min. available:" + avail );
  }
  
}

The new class looks like this:

class  extends
{
  String  ;     //  the artist
  String  ;     //  the music category

  // constructor will go here (skip for now)
  
  // show method will go here (skip for now)

}  

QUESTION 17:

Fill in the blanks. For now, leave out the constructor and the show() method.