• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Why do we need interfaces when we have abstract classes in java

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please let me know as to why do we need interfaces in the first place. Everything that can be done with interfaces can also be done with abstract classes. It has to do with multiple inheritence, but I'm not too clear about it. Please help.
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shyam!

I can just explain about interface is that when a class
implements a interface it actualy signs a contract with it ,that
this class is going to implement all the methods in an interface
and as you said what is the need for interface when we can
use abstract classes instead,but somtimes there is a requirement
that a class requires to implement more than one interface
or it requires to implement two different sets of methods
so it is possible
But if a class wants to implement more than one
abstract class you must
be knowing that multiple inheritence is not possible in java.......
i think this can be one reason for your question..............


i hope it helps...............
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaRanch FAQ provides the answer.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!