In interfaces the methods just defined without implementation then what is the purpose of defining the methods?

Showing Answers 1 - 9 of 9 Answers

lavankannan

  • Oct 5th, 2005
 

    The interface is just declared,so that u can use the methods were ever u want.the definition of the methods is given smewhere.it is easy to call the methods only with the method name.the method name refers and takes the declaration parts.

  Was this answer useful?  Yes

As By giving the Methods(Declaring) in Interface , We are telling to must follow exactly the same Signature for the given Methods. This wil be used when we are writing RMI Applications . Because in this case we just give the Interface to the User, so that user will come to know the Signature of the Method and later he/she will call it.

  Was this answer useful?  Yes

raviegp

  • Feb 27th, 2006
 

interfaces are meant for abstraction of data ie only method declarations are provided so that any class implementing the interface it will give the specific implementation according to the requirements.we must place only methods for which the implementation is user specific and not known at the time of designing the interface.

  Was this answer useful?  Yes

TDeepika

  • Mar 7th, 2006
 

In interfaces we implement the reusability& polymorphism concept. Each class that implements the interface is going to define the same method in its own way based on its conditions. with interfaces we can support dynamic method resolution at runtime .

  Was this answer useful?  Yes

RK

  • Apr 23rd, 2007
 

Interfaces are like Contract/Agreement that defines the precedure that we have to follow. When the class implements an interface, it guarantees that it has implemented the methods of the interface.

  Was this answer useful?  Yes

chaitu

  • Aug 8th, 2007
 

We declare methods in interfaces, by declaring these methods we provide signature of method to the class which implements this class.one interface can be implemented by any number of classes. By implementing interface classes follow the signature  given in the interface. The classes must overide all methods in interface.

  Was this answer useful?  Yes

An Interface force the end user to implement all the methods declared in the interface, in this way it is ensured that all the extending classes of a particular interface are implementing the same functionality but in their own specific way. for e.g there is an interface called Bank which has several methods now there are several other classes like CitiBank, HDFCBank which extends this Bank interface so they all have to implement the same methods defined in the Bank interface but the implementation logic of those methods could be different.

  Was this answer useful?  Yes

Thomas John

  • Sep 22nd, 2015
 

Interfaces is run time polymorphism. A class can extend one class and implement an interface. Another class can implement the same interface yet come from a different inheritance tree. So you treat an object by the role it plays rather than by the class type from which it was instantiated.
Many design patterns use interfaces. For example the command pattern
The fact that you cannot put implementation code turns out not to be a problem for most good designs because most interface methods would not make sense if implemented in a generic way.

  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