• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Anonymous Inner Class

 
ramesh maredu
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any one provide me syntax for anonymous inner class that extends a class or implements an interface
 
Sunil Belurgikar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interface:
Runnable r=new Runnable()
{


public void run() {

}

};


Class:
WindowAdapter f=new WindowAdapter(){};
 
ramesh maredu
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
I thought there is special syntax using implements and extends like.

Person person = new Person() implements comparable{
};

Sorry for silly question.
 
Sunil Belurgikar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interface:
Runnable r=new Runnable()
{


public void run() {

}

};


Class:
WindowAdapter f=new WindowAdapter(){};
 
Sunil Belurgikar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is that an anonymous class can either extend a class or implement a interface .
Anonymous class can extend a class which implements a interface , in that case anonymous class has to implement interface method in its body.
 
ramesh maredu
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anonymous class can extend a class which implements a interface , in that case anonymous class has to implement interface method in its body.


Anonymous class need not to implement interface method if its super class already implemented.

 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic