This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I know Interfaces are the means of defining abstract methods and then implementing those methods in the implementing class. But what purpose does Interfaces solve in Java Language. We have to implement the methods defined by the implementing interface, can't we do it without implementing interface ? We can straightly implement the required methods in our class without implementing interface ! So why to implement an interface ? Whats the use of interface , then ?
hi Sam, this clearly shows that u have not understood interfaces at all. I think if the concept of Interfaces was removed java would be useless. An interface in the simplest of terms is a contract with the implementing class where in the implementing class promises to provide implementation to all the methods declared in the interface. Thus it is a means of forcing a implementing class to definetly implement the methods specified in the interface. thus for example we have a interface like this interface Collection{ void clear();//removes all methods in collection } and as collections framework implements this interface(through abstractcollection) then i know any class that i use that extends the abstractcollection class, i can use the clear() method to remove all elements. thus it makes things simpler for the programer. regds. Rahul.
[This message has been edited by rahul_mkar (edited June 23, 2000).]
Going with Rahul, If you want certain classes in your application, to compulsarily have certain methods, then you can declare those methods within an interface. In this way, you can be assured that when a class says that it implements a particular interface, you will know, even without looking at the implementing class, the methods which you can invoke on it.