This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Anonymous Inner Class  RSS feed

 
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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!