Java Reference
In-Depth Information
LISTING 9.1
//********************************************************************
// Words.java Author: Lewis/Loftus
//
// Demonstrates the use of an inherited method.
//********************************************************************
public class
Words
{
//-----------------------------------------------------------------
// Instantiates a derived class and invokes its inherited and
// local methods.
//-----------------------------------------------------------------
public static void
main (String[] args)
{
Dictionary webster =
new
Dictionary();
System.out.println ("Number of pages: " + webster.getPages());
System.out.println ("Number of definitions: " +
webster.getDefinitions());
System.out.println ("Definitions per page: " +
webster.computeRatio());
}
}
OUTPUT
Number of pages: 1500
Number of definitions: 52500
Definitions per page: 35.0
version of the parent class. A dictionary has pages, because all books have pages;
but although a dictionary has definitions, not all books do.
Inheritance relationships are often represented in UML class diagrams. Figure 9.1
shows the inheritance relationship between the
Book
and
Dictionary
classes. An
arrow with an open arrowhead is used to show inheritance in a UML diagram,
with the arrow pointing from the child class to the parent class.
Search WWH ::
Custom Search