This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ass. 12.1 Base classes and derived classes 389 Date
The inheritance mechanism makes
all these members available in the
lower classes. (Note again that
these balloons do not belong to the
actual class diagram.) this_day
toString() This kind of arrow denotes inheritance between classes. The arrow
points to the base class (superclass)
that is inherited. BetterDate CurrentDate to_string_with_month_name()
to_american_format_string() This means that class BetterDate differs
from class Date in that it has two additional
methods. Class BetterDate has all those
fields and methods that are in class Date,
and in addition it has these two extra methods. When these sections are empty, it means that
class CurrentDate has exactly the same
members as its base class Date. These two
classes differ in that their constructors are different. Constructors are not always shown in
these kinds of class diagrams because it is well
known that classes often have constructors.
These diagrams do not attempt to describe
classes perfectly. The purpose is to give a general overview of the class structure. These are
not official UML diagrams Figure 12-1. Class diagram that describes relationships between three classes. 390 Chapter 12: Inheritance and class hierarchies Here, class CurrentDate inherits class
Date. The methods of class Date are available
methods for the objects of class CurrentDate. // CurrentDate differs from its superclass Date only in that its constructors are
different. The first constructor assumes the
American date print format.
The first constructor creates an object
of the standard Java class GregorianCalendar from which it can read the date
information that is maintained by the operating system of the computer. After these
assignment statements have been executed,
this CurrentDate object contains the date
of the computer.
Calendar and GregorianCalendar
are standard Java classes for handling
information related to dates and time in
Java programs. These classes will be discussed in a later chapter. CurrentDate.java (c) Kari Laitinen import
import java.util.Calendar ;
View Full Document
This document was uploaded on 01/20/2014.
- Winter '14