Holding References but not Using them

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:

Dear Amy,

Season's Greetings!

Dear Bob,

Love and Kisses,

XXX

Dear Cindy,

Happy 17th Birthday

Holding References but not Using them

What types of objects a reference variable can refer to:

A variable can hold a reference to an object whose class is a descendant of the class of the variable.

The class of the object must be a descendant of the class of the variable that holds a reference to that object. A descendant of a class is a child of that class, or a child of a child of that class, and so on. Siblings are not descendants of each other (you did not inherit anything from your brother, thank goodness.)

Note: there are some complications to this rule which are skipped in these notes, since you will probably never need to know them. Here are some variable declarations:

Card      c;
Birthday  b;
Valentine v;
Holiday   h

QUESTION 14:

Which of the following are correct?

c = new Valentine("Debby", 8);
b = new Valentine("Elroy", 3);
v = new Valentine("Fiona", 3);
h = new Birthday ("Greg",  35);