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 Abstract Class & Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract Class & Interface" Watch "Abstract Class & Interface" New topic

Abstract Class & Interface

Manu Dhanda

Joined: Jan 28, 2006
Posts: 23
I couldn't decide on it whether it's too simple or a tough question, so i thought to put it here only.

I just want to know the difference between an abstract class & an interface?
Why we just couldn't use the interfaces instead of abstract classes?

Am really seeking a satisfactory reply for it. Thanks.

"Books are as useful to a stupid person <br />As a mirror is useful to a blind person." <br /> <br />Chanakya quotes (Indian politician, strategist and writer, 350 BC-275BC)
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
Interfaces contain no implementation at all.

In an abstract class, you can have many methods that are implemented but leave some methods abstract so that different subclasses don't have to redo the work that's been done and they can override the abstract methods for their application.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199


Welcome to JavaRanch!

The best way to use an abstract class is as a way to partially implement an interface, letting multiple other classes extend it and complete the implementation. One example of this in the Java APIs is the class java.util.AbstractList. A number of other classes extend it, but no-one normally thinks about that. It just provides a sort of "starter implementation" of java.util.List. Other classes fill in the details.

[Jess in Action][AskingGoodQuestions]
Manu Dhanda

Joined: Jan 28, 2006
Posts: 23
But there are classes which are fully abstract? I mean all of their methods are abstract.
In that situation, what are the reasons to declare them abstract rather then declaring them an interface?

Partially implementing a class is one fact, but stil it's not the actual reason for declaring something abstract. Abstract is a tier that's been put between an interface and a class, but I couldn't see the exact reason for it.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
See also

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Manu Dhanda

Joined: Jan 28, 2006
Posts: 23
Thanks for the link.
I got some useful information there 'n further links for more info.

I agree. Here's the link:
subject: Abstract Class & Interface
jQuery in Action, 3rd edition