Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Shyam kumar
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.
 
dhwani mathur
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...............
 
Saket Barve
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaRanch FAQ provides the answer.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!