Results 1 to 4 of 4
- 09-01-2010, 07:24 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 13
- Rep Power
- 0
Why INTERFACE...pls tell me please....
If I need to implement an interface and just use its every methods name.Why shouldn't just write every methods statments in a class, not in interface??I only can think about that if I extend a class, than can implement another or the others interface.
so pls tell me why we use interface.any benefit?
- 09-01-2010, 07:28 PM #2
There was actually a thread on this very recently which you may find helpful: What is the point of Interfaces?
- 09-02-2010, 09:39 AM #3
Member
- Join Date
- Aug 2010
- Posts
- 35
- Rep Power
- 0
AFAIK (I am a beginner too!), interfaces are just that - "interfaces" - think of the real world - e.g. in a car - you could say that the steering wheel, pedals and gear stick are an interface. Of course, every car is different under the bonnet, but each one has those three controls (except for automatics, but only Americans use those ;)), which means that anyone who can drive one car can get into any other car and drive that too without having to know anything about how the car actually works.
As far as I have learned so far, the same concept applies in Java - you define an interface which can then be used by other classes to manipulate an object that implements the interface, but they don't need to know anything about what goes on inside the object - in fact the intention is that they don't know.
If this is wrong, I am sure that a Java Guru will correct me!
- 09-02-2010, 10:27 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
An interface is a contract between two parties; if both parties agree upon the API (the contract) on party can implement the contract at will while the other party can use the contract (the API) without changing any code. Suppose the implementer of the API finds a better method to do it all; the implementation can be changed without the user of the contract has to change anything. Closely related to this all is the rule "code to the interface, not the implementation".
kind regards,
Jos
Similar Threads
-
Interface?
By makpandian in forum New To JavaReplies: 5Last Post: 03-26-2009, 10:59 AM -
what is the need of interface?
By makpandian in forum New To JavaReplies: 1Last Post: 03-13-2009, 10:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks