go to previous page   go to home page  
Object obj;
YouthBirthday ybd = new YouthBirthday( "Ian", 4 );
String str = "Yertle";

obj = ybd;

if ( obj instanceof Card )  // Note changes here
  ((Card)obj).greeting();

else if ( obj instanceof String )
  System.out.print( (String)obj );

Answer:

Yes. After the fourth statement, obj points to a YouthBirthday object (that is a grandchild of Card) so instanceof returns true. The greeting() method of the Card object will run.


End of the Chapter

You have reached the end of the chapter. You may wish to review the following. Click on a subject that interests you to go to an instance of its discussion.

The next chapter will discuss interfaces— another object oriented aspect of Java.


go to previous page   go to home page