Results 1 to 2 of 2
  1. #1
    Lass is offline Member
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Usefulness of an Interface?

    I am learning java from the oracles doc, and I fail to see the usefulness of the interface. What is this interface used for? What would it do in a program?
    Thank you for your time.

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

    Default Re: Usefulness of an Interface?

    Quote Originally Posted by Lass View Post
    I am learning java from the oracles doc, and I fail to see the usefulness of the interface. What is this interface used for? What would it do in a program?
    Thank you for your time.
    Suppose a class D extends a class B and also suppose a method (from a completely unrelated class) expects a type I as a parameter; if there were no interfaces you would never be able to pass a D to that method because D already extends B and Java uses single inheritance (of implementation). In Java you can make D implement I so a D can be passed (as an I) to that method. Both a class and an interface are types; classes also have an implementation, while an interface hasn't.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 1
    Last Post: 07-08-2012, 05:23 PM
  2. Interface?
    By maknib in forum New To Java
    Replies: 52
    Last Post: 11-05-2010, 10:22 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
  •