• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to access an Inner Class' method

 
akaash singh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20990
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no you can't access any method added in annonymous inner class which is not present in it's super class.
 
akaash singh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic