difference between an Interface and an Abstract class

Discussion in 'Java' started by web development, Jun 19, 2009.

  1. web development

    web development New Member

    Joined:
    Jun 19, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    [FONT=Verdana, Arial, Helvetica, sans-serif]What is the difference between an Interface and an Abstract class?[/FONT]
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Here are some of them
    1. Abstract classes can have implementations for some of its members (Methods), but the interfaces can't have implementation for any of its members.
    2. An interface can extend another interface, but cannot extend an abstract class.
    3. All variable in interfaces are final by default
    4. Interfaces provide a form of multiple inheritance. A class can extend only one other class at least in Java and C#
    5. In Abstract Class atleast one of its method needs to be defined in subclass where as in interface all methods needs to be defined in subclass.
    6. Accessibility like Public/Private/protected are only allowed in abstract class and not in Interface
     
  3. gkumar

    gkumar New Member

    Joined:
    Jun 16, 2009
    Messages:
    58
    Likes Received:
    5
    Trophy Points:
    0
    1) Abstract class defines few or none of the methods, but
    interface defines all the methods..
    2) Abstract classes should have subclasses else that will
    be useless..
    Interfaces must have implementations by other classes else
    that will be useless
    3)only an interface can extend another interface, but any
    class can extend an abstract class..
    4)All variable in interfaces are final by default
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice