Results 1 to 4 of 4
  1. #1
    rohitjava is offline Member
    Join Date
    Aug 2010
    Posts
    13
    Rep Power
    0

    Lightbulb 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?

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    There was actually a thread on this very recently which you may find helpful: What is the point of Interfaces?

  3. #3
    XmisterIS is offline Member
    Join Date
    Aug 2010
    Posts
    35
    Rep Power
    0

    Default

    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!

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    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

  1. Interface?
    By makpandian in forum New To Java
    Replies: 5
    Last Post: 03-26-2009, 10:59 AM
  2. what is the need of interface?
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 03-13-2009, 10:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •