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 Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Class & Interface

 
Manu Dhanda
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Manu Dhanda
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See also http://faq.javaranch.com/view?InterfaceVsAbstractClass
 
Manu Dhanda
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link.
I got some useful information there 'n further links for more info.

Cheers..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic