Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

object of an interface? Hows possible  RSS feed

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



The above code is compilable. I wonder how can we make object of Interface Runnable.
What is this concept? :evil:
 
Sheriff
Posts: 21255
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search for the term "anonymous class".
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually this is not an object of an interface however in a piece of code like this one you are extending/implementing the specified class/interface and then you override the needed methods. this method is named anonymos classes. and if you ever written swing code all your listeners are generally created in this way.

 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Prime wrote:Search for the term "anonymous class".



DOH! Thanks Rob, I have been wondering about this myself for a while, makes perfect sense now!
ops:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!