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

abstract class

suneel kumar
Ranch Hand

Joined: Jan 08, 2007
Posts: 46
if my abstract class has all the abstract methods , can i call that class as an interface ?
Ricky Martaputra
Ranch Hand

Joined: Apr 04, 2005
Posts: 42
no, it is different..
  • 1. interface is not an object, while abstract class is..
  • 2 all variable in an interface is public static final, even you just declare int i, automatically it will be assigned into public static final int i.. but abstract class' variable is depending on what you've declared

  • Maybe there are plenty of differences.. But this is obviously the basic different.
    Cameron Wallace McKenzie
    author and cow tipper
    Saloon Keeper

    Joined: Aug 26, 2006
    Posts: 4968

    If your class has no instance variables, and none of the methods have an implementation, then indeed, you should re-type the class as an interface.

    "Programming to an interface" is a common goal and saying. This is probably what you should be doing.

    -Cameron McKenzie
    fejio few

    Joined: Jan 21, 2007
    Posts: 1
    The key difference between abstract class and interface is that abstract class is still a class, and should be used if it has a place within a class hiearchy. For example, if you're creating a graphical program that draws shapes, you will have a abstract class "Shape" and concrete subclasses "Rectangle", "Triangle", etc. And to make objects within the app draggable, you will create a "Draggable" interface that's implemented by all shapes, and other non-shapes objects.

    In other words, interface represents a capability that may be implemented by classes in any hierarchy. Whereas abstract class should be used if there's a natural "is-a" relationship and the capability of the abstract class is specific to its subclasses.
    I agree. Here's the link:
    subject: abstract class
    It's not a secret anymore!