Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Re: Abstract Classes

by Elgon (Curate)
on Apr 29, 2003 at 12:40 UTC ( #253939=note: print w/replies, xml ) Need Help??

in reply to Re: Abstract Classes
in thread Abstract Classes


This is exactly as I had it explained to me by those nice people at Sun when I did a Java course, what hardburn is describing sounds like an interface, as you say.

  • Abstract classes may or may not contain implementation for each of their methods and they may not be instantiated. There is no coercion of methods which the subclass must contain as any which are not implemented are inherited.

  • Interfaces are merely contracts which list the methods which an implementing class MUST have. They may not be instantiated either, but then again they aren't really classes and have no implementation so this should not be surprising

The utility of these two when used together correctly is that an Abstract Class provides common behaviours which subclasses will inherit, whereas an Interface merely defines methods which any extending class must implement. In the first case neanderthals and humans both have the same drink() method inherited from the hominids abstract class, which they extend. In the second case, both humans and fish MUST be able to breathe as they both implement the breathers interface but the actual mechanisms used are different.


If this node offends you, re-read it and reconsider. Think for a bit. I am almost certainly not trying to offend you, although I am frequently irreverent or flippant. Rememer - Please never take anything I do or say seriously.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://253939]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2021-10-19 12:40 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (76 votes). Check out past polls.