Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2012
    Location
    Mumbai
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Interfaces in JAVA

    What is the use of Interfaces in Java? Multiple Inheritance only!! I don't think so......Can someone explain me what were the many reasons for interfaces coming in existence

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Its a contract. Objects declared as an interface guarantee that they will contain the methods contracted by that interface. Since Java does not support multiple extends, interfaces are used to perform multiple inheritance, and because of the lack of multiple extends, interfacing is far more valuable in Java than extends ever will be.
    So yes, short version would be that interfaces are used for multiple inheritance as it allows you to interpret a single class as multiple datatypes.

  • #3
    New Coder
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Advantages
    Interfaces are mainly used to provide polymorphic behavior.
    Interfaces function to break up the complex designs and clear the dependencies between objects.
    Disadvantages
    Java interfaces are slower and more limited than other ones.
    Interface should be used multiple number of times else there is hardly any use of having them.
    Last edited by soniavdavidson; 09-05-2014 at 08:23 AM.

  • #4
    New Coder
    Join Date
    Sep 2014
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Using an interface allows you to hide implementation details of a class from other classes that call it: advantages include hiding messy configuration stuff as well as the ability to use multiple implementations of the interface that are otherwise disparate.
    In programming, we often define the interfaces before we write the implementing classes that implement them: they define what we need and want them to do.


  •  

    Tags for this Thread

    Posting Permissions

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