File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Interface vs Abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface vs Abstract class" Watch "Interface vs Abstract class" New topic

Interface vs Abstract class

prat de

Joined: Sep 15, 2003
Posts: 22
why to use Interface in java if we can accomplish the same thing by using Abstract 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

Joined: Nov 27, 2001
Posts: 1561
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?

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Gayathri Prasad
Ranch Hand

Joined: Jun 25, 2003
Posts: 116
The support for multile inheritance is achieved through interfaces. Thus interfaces are required and thus both are porvided.

Prasanna Kumar R.V
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Interface vs Abstract class
It's not a secret anymore!