File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inner class" Watch "inner class" New topic
Author

inner class

cybel sheriden
Ranch Hand

Joined: Jan 18, 2005
Posts: 50
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

Joined: Nov 20, 2003
Posts: 97
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,


Jimmy Die
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inner class
 
Similar Threads
immutable class
inner classes
Regarding abstract class
why can't we instantiate abstract class
how abstract class constructor invokes while creating instance of Subclass