• Post Reply Bookmark Topic Watch Topic
  • New Topic

interface  RSS feed

 
S Babs
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is interface? Why and how it will be useful?
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi:
please refer to Interface Concept, Interface Concept, and Java Concept.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface is like a blueprint.
You are telling other programmers (and the JVM) that this class WILL implement whatever it takes to meet the requirements of this interface. What makes this so useful is that this means that the JVM can handle your class as though it were of the type of the interface and be confident that it will work. So you can assign an object of your class to any variable that has the type of the interface that it implements.
List myList = new ArrayList();//can be handled as TYPE List
If you try to include all the proper methods of the interface but do not specifically STATE that you are implementing the interface, then the JVM will NOT be confident that all is well and will NOT allow you to assign an object of your class to a variable of the interface type.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!