This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract & Interface

 
Siva kandasamy
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new this forum and new to Java.
In this forum, many explained the difference between the abstract and interfaces.
Does any one knows, what is the driver behind these two architecture which looks
pretty similar.
I mean, Why interfaces ?
What is that we can't achieve by having abstract class, we needed interface vice versa ?
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out this article, it helped answer this question for me when I read it awhile back.
designing with interfaces
HTH,
E
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces provide the ability to have multiple inheritance.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Expanding a bit more: The C++ language allowed a more powerful form of multiple inheritance, and the Java language designers felt that this caused problems more often than it solved them. They felt that multiple inheritance of method declarations was a good thing, but multiple inheritance of method implementations was bad. So you can inherit as many declarations as you want, if they're defined in interfaces - but you can only directly inherit from one class. This inherited class may be an abstract class if there's at least some implementation which you wish to inherit, but if it doesn't make sense to provide a complete implementation (usually because you need the flexibility to implement some things differently in different classes, and there's no single "default behavior" for every method that makes sense to put in a base class).
Definitely check out the JavaWorld article Eric cited for more info.
[ December 31, 2002: Message edited by: Jim Yingst ]
 
Siva kandasamy
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks & Happy New Year.
-siva
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic