Is this code correct?
YouthBirthday birth; birth = new Birthday( "Terry", 23 );
No. A reference variable for a child class (YouthBirthday) cannot hold a reference to an object of a parent class (Birthday).
YouthBirthday
Now let us re-write YouthBirthday
in order to show more about polymorphism.
Say that you want two greeting()
methods
for YouthBirthday
:
greeting()
method.
Fill in the missing parts.