"Rajarshi Guha" <> wrote in message
news

...
> Hi,
> I've been brushing up on Java and had a question regarding use of
> abstract class and interfaces.
>
> As I understand an abstract class is only useful if I want to use it as a
> superclass since it cannot be instantiated. However I also see that an
> interface also essentially serves the same purpose in that it cannot be
> instantiated and is generally used as a superclass in hierarchies.
>
> So what *is* the difference between these two constructs? And why would
> I prefer one over the other?
>
> Thanks,
>
>
> --
> -------------------------------------------------------------------
> Rajarshi Guha <> <http://jijo.cjb.net>
> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
> -------------------------------------------------------------------
> Q: What's purple and commutes?
> A: An abelian grape.
>
Generally, an interface defines no implementation, an abstract class
provides partial implementation, and a concrete* class provides complete
implementation. Or another way of thinking about it is that interfaces
provide 0% implementation, abstract classes between 0 and 100% (inclusive)
implementation and concrete classes 100% implementation.
Therefore, interfaces provide no method implementations (all abstract), an
abstract class can provide some method implementations, and some not
(abstract), and a concrete class provides all method implementations. A
common strategy of using all three is to provide a common interface, which
serves as the super type, and abstract class that provides method
implementations that will be common to most subtypes, and concrete classes
that inherit from the abstract class to provide complete implementation.
--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)