Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

For interfaces are required ?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!