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

Answer:

No. Remember that Java is single inheritance.


Video Store Example

Movie as a child of Video

Programming in Java is done by creating class hierarchies and instantiating objects from them. You can extend your own classes or extend classes classes that already exist. The Java Development Kit gives you a rich collection of base classes that you can extend as needed.

(Some classes are declared final and can't be extended.)

Here is a program that uses a class Video to represent videos available at a store. Inheritance is not explicitly used in this program (yet).


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

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

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

  public String toString()
  {
    return title + ", " + length + " min. available:" + avail ;
  }
  
  public String getTitle() { return title; }
  public void setTitle( String ttl ) { title = ttl; }
  public int getLength() { return length; }
  public void setLength( int lng ) { length = lng; }
  public boolean getAvailable() { return avail;}
  public void setAvailable( boolean avl ) { avail = avl;}
}

public class VideoStore
{
  public static void main ( String args[] )
  {
    Video item1 = new Video("Jaws", 120 );
    Video item2 = new Video("Star Wars" );

    System.out.println( item1.toString() );
    System.out.println( item2.toString() );     
  }
}

Copy this program to an editor, save it to VideoStore.java, and run it.

If you are using BlueJ, copy each class into a separate file.


QUESTION 9:

What does this program print?


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