locked
Difference between Abstract class and Interface

    Question

  • What is the difference between an abstract class and an interface ?
    Sunday, April 08, 2012 10:40 AM

Answers

  • So basically the main difference is

    An Abstract class can contain implementation i.e. normal methods plus abstract methods.

    But Interface can not contain implementation i.e. only declaration and no defination.

    • Marked as answer by Amey Kelkar Sunday, April 08, 2012 11:06 AM
    Sunday, April 08, 2012 11:05 AM
  • No. But you can do it like:

    public interface MyInterface 
    {
        bool Foo();
    }
    
    public abstract class MyAbstractClass : MyInterface
    {
        public abstract bool Foo();
    }


    Mitja

    Sunday, April 08, 2012 11:16 AM

All replies

  • Read here. Its all very and simply explained.


    Mitja

    Sunday, April 08, 2012 10:46 AM
  • So basically the main difference is

    An Abstract class can contain implementation i.e. normal methods plus abstract methods.

    But Interface can not contain implementation i.e. only declaration and no defination.

    • Marked as answer by Amey Kelkar Sunday, April 08, 2012 11:06 AM
    Sunday, April 08, 2012 11:05 AM
  • But can an Interface contain an Abstract method ?
    Sunday, April 08, 2012 11:06 AM
  • No. But you can do it like:

    public interface MyInterface 
    {
        bool Foo();
    }
    
    public abstract class MyAbstractClass : MyInterface
    {
        public abstract bool Foo();
    }


    Mitja

    Sunday, April 08, 2012 11:16 AM
  • Monday, April 09, 2012 6:04 AM
  • Hi,

    Check this link difference between an abstract class and an interface


    PS.Shakeer Hussain

    Monday, April 09, 2012 6:32 AM