aspose file tools
The moose likes Beginning Java and the fly likes Why do we need interfaces when we have abstract classes in java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Why do we need interfaces when we have abstract classes in java" Watch "Why do we need interfaces when we have abstract classes in java" New topic
Author

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

Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
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

Joined: May 08, 2007
Posts: 621
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

Joined: Dec 19, 2002
Posts: 224
JavaRanch FAQ provides the answer.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Why do we need interfaces when we have abstract classes in java
 
Similar Threads
abstract interface?
Why to use interfaces insted of Abstract Classes in some places?
Doubt
Difference between interfaces and abstract classes
Interfaces and Abstract Classes