Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Abstract vs interface

  Asked By: Seth    Date: Mar 29    Category: Java    Views: 897

I've just read about abstract class and interface.
in what case do we implement them??
and why this distinction?



1 Answer Found

Answer #1    Answered By: Maurice Hanson     Answered On: Mar 29

Any class  can only extend one other class but it can implement  many interfaces.
Interfaces can have no implementation code whereas abstract  classes can
implement some methods while leaving others abstract. As to when you implement
either one of them, it depends largely on what you are doing. Interfaces are
useful as contracts (i.e. for plugins), callbacks, etc. Abstract classes are
useful for providing partial base implementations (shared functionality) while
still providing for extension. Often you may want to provide an interface  and
then an abstract base class which implements some of that interfaces standard

Didn't find what you were looking for? Find more on Abstract vs interface Or get search suggestion and latest updates.