Why do we need interface in Java. Instead of interface we can write the methods in the class itself. Why do we need seperate interface?

Showing Answers 1 - 33 of 33 Answers

Guest

  • Jun 29th, 2006
 

Java don't support Multiple Inheritance. For that we can use Interface.

Interface is like the getway to comunicate between to classes.

Not always we write methods in Interface, we can also create objects in the Interface. The Object which will be shared between two classes can be created in an Interface.

Creating Seperate Interface is one of the key factor of Software Engineering. Suppose Class "A" has many methods depends on several Classes' objects. Think that, one method creates connection depends on Class B object and another method makes business rules depending on Class C object. In this situation, you can actually use to Seperate Interface for better performence.

  Was this answer useful?  Yes

rabbi

  • Jun 29th, 2006
 

some times you want to hide your detail implementation , you can use interface as a representation of a class and interface method is like abstract so implementation depends on the client class.

  Was this answer useful?  Yes

Pranita

  • Jul 17th, 2006
 

Interface acts as communicator for the classes.since interface contains many empty bodies in it so diffrent implementations can be provided for same method as per its use in diffrent classes so interfaces are needed.

  Was this answer useful?  Yes

vkg_16my

  • Mar 1st, 2008
 

interface is the contract between two party where one party will implement to that contract and other party will use that contract  to invoke the implementation. that means contract will remane same but implementation can vary freely.
Example --> collection calsses, RMI..............

sampra

  • Mar 6th, 2008
 

for this question we have lot of reason java supprt runtime polymorphism so for that we have to take ref var of interface and implementation  in sub class so for that  we need interface

  Was this answer useful?  Yes

ankit.mca4

  • Mar 28th, 2009
 

A class can contain multiple interface. If B class want to define two methods of class A and class C wants three methods of class A then class A implements two interface one for B and another for C.

  Was this answer useful?  Yes

kajal

  • Sep 28th, 2011
 

if we want the concept of multiple inheritance in java than we use interface.

  Was this answer useful?  Yes

dust

  • Oct 25th, 2011
 

interface basically provides a hierarchy of methods so we only implement that particular interface instead of making the instance of that .....ok

  Was this answer useful?  Yes

punyamca

  • Feb 6th, 2015
 

for late binding purpose. to design a method so that a part of functionality has to be mentioned by end user(implementing class)

  Was this answer useful?  Yes

Bhavesh

  • Feb 28th, 2015
 

To get the hierarchy of classes that I might need later.

We don’t want the user to know what functionality it offers other than some important We also dont want user to use reflection to exploit functionalities

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions