Card Hierarchy

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:

Yes. Since the child did not define a method with the same signature and same return type as the parent, it must be declared to be abstract. It is OK to have an abstract child of an abstract parent.

Card Hierarchy

card hierarchy

Let us use the hierarchy of classes used in the previous chapter to illustrate these ideas. The diagram shows that the class Card is an abstract class (which, therefore, cannot be instantiated.)

Card has a single abstract method, greeting(). The other three classes are ordinary classes which can be instantiated. They inherit from Card, so each must define a greeting() method which is not abstract.

QUESTION 5:

(Review: ) Say that a method is invoked as here:

referenceVariable.greeting()

What determines which method is run? The class of the reference variable or the class of the object?