This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what is an interface  RSS feed

 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii,



how do you define an interface?

anil
 
Hareesh Ram Chanchali
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please refer

http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html
 
Amit Biswas
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A short and sweet defition maybe like :-

An interface is a description of a set of methods that conforming implementing classes must have.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the definational usage, I feel that all communication between layers of software systems should take place using concrete implementation of interfaces.
Makes it easy for testing too.You could even the testcases to for the layer before even the actual classes are coded.
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to add that interfaces can define other elements such as constants that are inherited by classes that implement those interfaces. Interfaces can also include other things in addition to method and constant declarations.

-- Kaydell
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

also if a class implements an interface, objects of this class are "instanceof" the interface.
So you can make e.g. ArrayLists of the interface type and invoke the method(s) the interface has on any of its implementers.


Prints
Boat swimming
FinnDingi swimming
ready to jibe?
Shark swimming

Classes that extend an implementer inherit the interface methods (the methods must be public), so they are also instanceof the interface, like the FinnDingi.



Yours,
Bu.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!