Abstract Class

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

"Cards" — even though everything in the box is a specific type of card the box would be labeled with the general idea "Cards."

Abstract Class

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 children 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.

QUESTION 3:

Which of the card types has a greeting() method?