You must Sign In to post a response.
  • Category: .NET

    What is the difference between abstract and interface?

    Please give me the clear points.
  • #275466
    Abstract Class:

    1. Abstract Class Can contain Abstract Methods and Non-
    Abstract Methods.

    2. When a Non-Abstract Class is Inherited from an Abstract
    Class, the Non-Abstract Class should provide all the
    implementations for the inherited Abstract Method.


    1. Interface is nothing but Pure Abstract Class ie
    Interface can contain only the function declaration.

    2. All the members of the interface are Public by Default
    and you cannot provide any access modifiers.

    3. When a class is inherited from the interface, the
    inherited class should provide actual implementations for
    the inherited members.

  • #275469

    A class implementing an interface must implement all of the methods defined in the interface, while a class extending an abstract class need not implement any of the methods defined in the abstract class. Additionally, a class extending an abstract class can implement an infinite number of it's own methods.

    another key difference between abstract class and interface is that , in abstract class we can put sharable code, but that is not possible in case of interface.

    Another key difference between abstract class and interface is that,

    We can use interface as marker, ( we can use abstract class also as abstract but then we can't extends any oter class, so it is better always use interface as marker)

  • #275478
    Adding more ,

    Use abstract classes and interfaces in combination to optimize your design trade-offs.
    Use an abstract class
    * When creating a class library which will be widely distributed or reused—especially to clients, use an abstract class in preference to an interface; because, it simplifies versioning. This is the practice used by the Microsoft team which developed the Base Class Library. (COM was designed around interfaces.)
    * Use an abstract class to define a common base class for a family of types.
    * Use an abstract class to provide default behavior.
    * Subclass only a base class in a hierarchy to which the class logically belongs.

    Use an interface
    * When creating a standalone project which can be changed at will, use an interface in preference to an abstract class; because, it offers more design flexibility.
    * Use interfaces to introduce polymorphic behavior without subclassing and to model multiple inheritance—allowing a specific type to support numerous behaviors.
    * Use an interface to design a polymorphic hierarchy for value types.

    * Use an interface when an immutable contract is really intended.

    * A well-designed interface defines a very specific range of functionality. Split up interfaces that contain unrelated functionality

  • #275511
    Interface Class:-
    1)All The Methods are Abstract.its a pure Abstract Class
    2)There No Access Modifier by Default : Public
    3)There is No implementtation

    Abstract Class:-
    1)Abstract Class can have Abstract Methods and Non-Abstract Methods.
    2)All The Access Modifiers Allowed in Abstract Class
    3)implementtation Allowed in Abstract Class

    i hope this may help u.

    Thanks & Regards
    Nothing is mine ,Everything is yours!!!

  • #275518
    Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. Inteface is a Java Object containing method declaration and doesn't contain implementation. The classes which have implementing the Interfaces must provide the method defination for all the methods.2. Abstract class is a Class prefix wtih a abstract keyword followed by Class definaton. Interacace is a Interface which starts with interface keyword.3. Abstract class contatins one or more abstract methods. where as Interface contains all abstract methods and final declarations.4. Abstract class contains the method defination of the some methods. but Interface contains only method declaration, no defination provided.5. Abstract classes are useful in a situation that Some general methods should be implemented and specialization behaviour should be implemented by child classes. Interafaces are useful in a situation that all properties should be implemented we can use this scenario

  • #275688
    Differences between Abstract Class and Interface :
    Abstract Class:
    * can contain access modifiers for subs,properties and functions.
    * a class may inherit only one abstract class.
    * can contain defined fields and constants

    Interface :
    * cannot contain access modifiers for subs,properties and functions.
    * a class may inherit several interfaces.
    * cannot contain any defined fields and constants.

    Please rate this post, if it is useful for you.

    Thanks & Regards

  • #277006
    Verify this link..This may help u..

    Sridhar R
    Nothing is illegal, Until You Get Caught

  • #289735

    Before putting any question in the forum, please search for it if the answer is already available in dotnetspider website. Because so many people are asking the same question about interface and abstract class. Please do not repeat the same questions again and again. There is a searchbox at the top right of the dotnetspider website. You can search for the answer by using that search box. If you do not find any answer, then you can post the question in the forum.

    Web Master

    Web Master

  • #295816

    Interfaces are similar to abstract classes.However,interface represent the highest level of abstraction in object-oriented programming.This is because all the methods in an interface are abstract and do not have implementation.In contrast,the abstract classes that are created using Abstract keyword might contain a method that has a body.


    Thanks & Regards


  • #298567

    Following are the difference between abstract and interface,

    1>Abstract class having method declaration as well as method method definition whereas interface having method declaration only.

    2>Abstract class are known as partial abstract class whereas interface is known as fully abstract class.

    3>Abstract class features we have to inherit to the child class whereas interface features we have to implement in the child classes.

    4>Abstract class support access specifiers whereas interface doesn't support access specifiers.

    5>Abstract class have normal variable as well as constant variable whereas interface have only constant variables.

    6>We can write constructor in abstract class whereas we can't write constructor in interface.


    Thanks & Regards


  • #307363
    Following are the differences

    • Interface contains methods that must be abstract; abstract class may contain concrete methods.
    • Interface contains variables that must be static and final; abstract class may contain non-final and final variables.
    • Interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces.
    • Interface is absolutely abstract; abstract class can be invoked if a main() exists.
    • Interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces.
    • Members in an interface are public by default; abstract class may contain non-public members.
    • Interface is used to "implements"; whereas abstract class is used to "extends".
    • Interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance.

    Thanks and Regards
    Meetu Choudhary

    Thanks and Regards
    Miss Meetu Choudhary (Site Coordinator)
    Go Green Save Green

  • #309690

    Thanks and Regards
    Miss Meetu Choudhary (Site Coordinator)
    Go Green Save Green

This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.