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.
The moose likes Java in General and the fly likes For interfaces are required ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "For interfaces are required ?" Watch "For interfaces are required ?" New topic
Author

For interfaces are required ?

Sam
Greenhorn

Joined: Jun 23, 2000
Posts: 26
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 ?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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).]
Shriram Shivakumar
Ranch Hand

Joined: Jun 20, 2000
Posts: 42
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.

-Shriram Shivakumar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: For interfaces are required ?
 
Similar Threads
abstract class
Interfaces in Java
why to implement interface
interface
Can anybody answer these questions?