"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.
This is useful to do,
just as a store has all its greeting cards
in one display, but grouped 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 children classes inherit from the abstract parent class.
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.
Which of the card types has a greeting()
method?