This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes object of an interface? Hows possible Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object of an interface? Hows possible" Watch "object of an interface? Hows possible" New topic
Author

object of an interface? Hows possible

Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Hi,



The above code is compilable. I wonder how can we make object of Interface Runnable.
What is this concept? :evil:


Perform for today. Adapt for tomorrow.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Search for the term "anonymous class".


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
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.


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
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:

be a well encapsulated person, don't expose your privates, unless you public void getWife()!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: object of an interface? Hows possible