The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
May 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Abstraction

Posted by Matt Gerrans on November 05, 2001 at 1:48 PM

Neither can be instantiated. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

Use interface as much as possible and only use an abstract class in the case where you want to provide some (but not all, of course) implementation. In practice, you want to prefer using, passing and returning interfaces, not abstract class references. I think even in the case where you have an abstract class to share some implementation, you still want to have an interface represent what will be used by the client (for an example look at the new Collections -- you often pass around Collection, List, Set or Map references, but not a AbstractList, AbstractSet or AbstractMap, references).

- mfg


> > > Hi,
> > > I have general question, What is the different between interface and abstract class. When to go for Interface and When to go for Abstract class.
> > > Thanking you,
> > > With Regards,
> > > shoeb






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us