wood burning stoves 2.0*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract Class & Interface" Watch "Abstract Class & Interface" New topic
Author

Abstract Class & Interface

Manu Dhanda
Greenhorn

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: 2367
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
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

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
Greenhorn

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
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
See also http://faq.javaranch.com/view?InterfaceVsAbstractClass


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
Greenhorn

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

Cheers..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract Class & Interface