"Cards" — even though everything in the box is a specific type of card the box would be labeled with the general idea "Cards."
For this example,
all card objects are one of the three types
(Valentine
, Holiday
, or Birthday
)
and the parent class Card
is used only to group them into a hierarchy.
There will never be an object that is just a card.
This is useful to do,
just as a store has all its various greeting cards
in one display, arranged into several categories.
An abstract class in Java is a class that is never instantiated. Its purpose is to be a parent to several related classes. The child classes inherit from the abstract parent class.
In hierarchy drawings (such as on the previous page), abstract classes are drawn with dotted lines. An abstract class is defined like this:
abstract class ClassName
{
. . . . . // definitions of methods and variables
}
Access modifiers such as public
can
be placed before abstract.
Even though it can not be instantiated,
an abstract class can define methods and variables that
children classes inherit.