Understanding Chapter 2 Q 22 of A Little Java, A Few Patterns -
in chapter 2 of a little java, few patterns, question 22 is:
are there onions on shish^d:
new skewer()?
answer is:
true, because there neither lamb nor tomato on new skewer().
skewer subclass of shish^d, onion subclass of shish^d, don't understand why there onions on new skewer()
, explain bit further?
i've googled book , although pages missing, think question's about:
shish s = new skewer(); system.out.println(s.onlyonions()); //prints true;
it prints true because onlyonions()
declared abstract
in super class shish
, overriden in skewer
class follows:
class skewer extends shish { @override boolean onlyonions(){ return true; } }
so should clear s.onlyonions()
returns true, since s' dynamic type skewer
.
Comments
Post a Comment