go to previous page   go to home page   go to next page

Answer:

Dear Amy,

Season's Greetings!

Dear Bob,

Love and Kisses,

XXX

Dear Cindy,

Happy 17th Birthday

Descendants

What types of objects can a reference variable 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.


QUESTION 14:

Here are some variable declarations:

Card      c;
Birthday  b;
Valentine v;
Holiday   h

Which of the following are correct? (click on the statement to confirm your answer)

c = new Valentine("Debby", 8);

b = new Valentine("Elroy", 3);

v = new Valentine("Fiona", 3);

h = new Birthday ("Greg",  35);