aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How to access an Inner Class' method 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How to access an Inner Class Watch "How to access an Inner Class New topic
Author

How to access an Inner Class' method

akaash singh
Ranch Hand

Joined: Jul 04, 2009
Posts: 45
Hi ,

Is there a way to access an Inner Class' method which is not an overridden version of the superclass' method.
as in

class PopCorn{
public void Pop(){ }
}

class F
PopCorn p = new PopCorn(){
public void pop() {}
public void f1(){} // how can we access this
}
}

And is it possible to have an anonymous class without it being asscoiated with a superclass ?

Regards ,
Akash
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

Actually neither of those questions are limited to inner classes. If you try your PopCorn example as a top-level class which extends PopCorn, the same question arises. (And it has the same answer.)

Likewise you can't declare any class -- anonymous or otherwise -- which isn't a subclass of another class. If nothing else, a class you declare is a subclass of Object.
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
no you can't access any method added in annonymous inner class which is not present in it's super class.


SCJP 1.5(97%) My Blog
akaash singh
Ranch Hand

Joined: Jul 04, 2009
Posts: 45
Likewise you can't declare any class -- anonymous or otherwise -- which isn't a subclass of another class. If nothing else, a class you declare is a subclass of Object.
Paul Clapham . Ok , apart from the Object .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access an Inner Class' method
 
Similar Threads
Anonymous Inner Classes doubt
K&B Anonymous Inner Class.
Accessing primitives in anonymous inner class
Anonymous inner class
Anonymous inner classes