Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class

 
cybel sheriden
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

chapter 8 of k&b page 470

how do we access the new method sizzle()of the child class(annoymous class)
since by polymorphism it is not a known to the parent class .so is it like we can call only the overridden methods.
 
Jimmy Die
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If you re-read the opening paragraph on that page (470) it mentions "You can only call methods on an anonymous inner class reference" here is the important part "that are defined in the reference variable type!"

So in this example the reference variable type is Popcorn and p is the reference variable. So because sizzle() is not defined in Popcorn it can't be called polymorphically (I feel so smart using the word polymorphically ) So sizzle() must be defined in some way in Popcorn class for it to be used. The whole chapter is worth re-reading to secure differences between Inner classes and anonymous inner classes, and how to reference the methods and variables, etc...


Good luck,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic