• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface instance  RSS feed

 
hhabib rahman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Is it possible to create a instance for Interface? If possible how can create the instance, and what is the use of it?
 
Valery Lezhebokov
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by hhabib rahman:
Hi
Is it possible to create a instance for Interface? If possible how can create the instance, and what is the use of it?


1. Possible
2. When you assign listeners you give an interface instance as a paremeter in addXXXListener method...
 
Valery Lezhebokov
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last post means that you can have instance for CLASS which implements certain interface. Sorry for confusing.
 
neetika sharma
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not instantiate an interface,however, u can create its reference variabe.

You can just assign an object of a class (implementing the interface) to the reference variable of the interface.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An anonymous inner class looks a lot like an instance of an interface. I think this is pretty close:

In fact it's not an instance of an interface but an instance of a tiny class defined on the spot. It's a slick thing to have put into the language.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!