File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object of an interface? Hows possible" Watch "object of an interface? Hows possible" New topic

object of an interface? Hows possible

Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132

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

Joined: Oct 27, 2005
Posts: 20271

Search for the term "anonymous class".

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!

be a well encapsulated person, don't expose your privates, unless you public void getWife()!
I agree. Here's the link:
subject: object of an interface? Hows possible
jQuery in Action, 3rd edition