Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract class

 
suneel kumar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if my abstract class has all the abstract methods , can i call that class as an interface ?
 
Ricky Martaputra
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 4968
    1
    Hibernate Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic