Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Differences between 'Interface' & 'Abstract Base Class' ? Please !!

kishore_peddikishore_peddi Member Posts: 176

Hi,

Good day. Can you please explain what do you mean by 'Interface' and 'Abstract Base Class' and what are the differences between those two ?.

Advance ThanX for your time & patience.

Bye...
kishore

Comments

  • kreitlerkreitler Member Posts: 218
    [b][red]This message was edited by kreitler at 2003-7-5 10:15:52[/red][/b][hr]
    Hi Kishore,
    The concepts of 'interface' and 'abstract base class' are similar in a lot of ways, which makes it easy to confuse them. Here's are some basics for both:

    An 'interface' declares a set of methods.
    Any class which implements the interface MUST define these methods and fill out their internal code.
    *Any* class can implement an interface, regardless of its place in the inheritence hierarchy.

    An abstract class establishes a set of methods and instance variables that child classes will inherit.
    Some of the methods may be declared 'abstract', in which case, the child classes MUST define the code for those methods.
    Only classes which inherit from the abstract class can define and use the methods of the abstract class.

    Said another way, using an interface is like joining a club. You have to meet the club requirements, but other than that, anyone can join, and you can belong to multiple clubs.

    For example, in order to join the tennis club, you have to know the rules of tennis. Same thing for the chess club. However, as long as you know both tennis and chess, you can belong to both clubs at once.

    In contrast, abstract classes act like a long-lost father. He isn't around, so he can't do anything directly. However, he has passed on to his offspring certain special abilities: great teeth, a talent for art, etc. Furthermore, only his children get these benefits, and each child can have only one father.

    I hope that helps, but if you want more info (and a more technical presentation), check here:

    http://www.javaworld.com/javaworld/javaqa/2001-04/03-qa-0420-abstract.html

    Good luck,

    Kreitler



    :
    : Hi,
    :
    : Good day. Can you please explain what do you mean by 'Interface' and 'Abstract Base Class' and what are the differences between those two ?.
    :
    : Advance ThanX for your time & patience.
    :
    : Bye...
    : kishore
    :
    :



  • padmanjalipadmanjali Member Posts: 1
    Hi
    Abstract class contains both concrete methods and as well as abstract methods.Means concrete methods means it contains both declaration part and definition part.abstract methods means it contains only declaration part.when u writing abstract classes using key work is abstract.

    interfaces are implycitly pure abstract methods only.its members are static and final.when u r using this one u must implement that methods decaring as public.

    using this interface java provides the concept of multiple intheritence.
Sign In or Register to comment.