• Post Reply Bookmark Topic Watch Topic
  • New Topic

Instantiate Interface?  RSS feed

 
kiran nyala
Ranch Hand
Posts: 55
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we instantiate an Interface if yes How?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would you do with an instance of an interface?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, only classes can be instantiated. Java has a syntax that makes it possible to create an anonymous class that implements an interface, though, and that *can* be instantiated:
 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the post today about "inner classes" and find the post by Pradeep Kumar and his link. That article shows the use of an interface (xxxListener) as an anonymous inner class. That is the nearest I can think of to instantiating an interface.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!