• Post Reply Bookmark Topic Watch Topic
  • New Topic

small doubt in interface..  RSS feed

 
s.palanivel rajan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we create instance for an interface...
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. You can create an instance of an anonymous inner class that implements an interface, but that's really not the same thing, even though it looks like you are instantiating that interface.
 
swapnl patil
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface does not provide any implementation and is, therefore, abstract by definition. This means that it cannot be instantiated, but
classes can implement it by providing implementations for its method prototypes. Declaring an interface abstract is superfluous and
seldom done.

Interfaces with empty bodies are often used as markers to tag classes as having a certain property or behavior.
Example : java.lang.Cloneable, java.io.Serializable,
java.util.EventListener.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!