File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface vs Abstract class

 
prat de
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why to use Interface in java if we can accomplish the same thing by using Abstract Class...in terms of defering implementation of methods..
please let me know if any of my friends here can answer this question
- prat.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm.. good question..
probably because an interface is 100% abstract class (you cannot have any method with a body), whereas in an abstract class you can even have no abstract methods at all (although IMO it wouldn't make sense to declare it as abstract).
I think the interface gives more flexibility than an abstract class.
any other opinions?
 
Gayathri Prasad
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The support for multile inheritance is achieved through interfaces. Thus interfaces are required and thus both are porvided.
Cheers,
Gaya3

------------------------------------------
Prasanna Kumar R.V
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Why Extends Is Evil. Allen Holub cautions us to think twice before extending a class, and illustrates how interfaces leave much more flexibility for the future.
I've used abstract classes in frameworks, where some functionality is provided and the extending class can override "developer hook" methods to plug in additional functionality. Holub fairly well rips up the MFC for doing this, so maybe I shouldn't admit it so freely.
[ September 16, 2003: Message edited by: Stan James ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic