locked
Diference between abstract class and interface

    Question

  •  

    Hi,

     

    I had a doubt on basic concept of interface and abstract class.

     

    I had idea of wht is interface and abstract class but there is case ,can any do justification on these case is

     

    Abstract class is a clas where some methods r defined and some are abstract methods.

    Interface is where all methods are abstract .

     

    but what happen if i try to maintaince all methods in abstract class as abstract which is equivalent to interface.?

     

    We go for abstract class if want to extend functionality of class.For interface if we wanna implement a new implementation.

     

    is there any other difference apart from this and other issues if we try to have all methods abstract .

     

     

    With regards

    Mahender

    Friday, December 21, 2007 1:27 PM

Answers

  • You can derive from multiple interfaces but not multiple classes

    Friday, December 21, 2007 9:06 PM
  • You can also provide some of the implementations inside an abstract class where you can't with an interface
    Abstract classes doen't require that all members be abstract as well, it does however imply that any derivation must implement for itself any member marked with abstract.

    ie: This is valid with an abstract class but not an Interface

    Code Block

        public abstract class Something
        {
            public void ShowMessage( string s )
            {
                MessageBox.Show( s );
            }
        }


    Abstract (C#)
    Friday, December 21, 2007 10:15 PM
  • Please refer to the following thread.

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2545998&SiteID=1

     

    Moreover, please retrieve it by the key word "interface abstract class" in this forum and the
    relating forum.

    A lot of profitable information is found.

    Sunday, December 23, 2007 3:58 AM

All replies

  • You can derive from multiple interfaces but not multiple classes

    Friday, December 21, 2007 9:06 PM
  • You can also provide some of the implementations inside an abstract class where you can't with an interface
    Abstract classes doen't require that all members be abstract as well, it does however imply that any derivation must implement for itself any member marked with abstract.

    ie: This is valid with an abstract class but not an Interface

    Code Block

        public abstract class Something
        {
            public void ShowMessage( string s )
            {
                MessageBox.Show( s );
            }
        }


    Abstract (C#)
    Friday, December 21, 2007 10:15 PM
  • Please refer to the following thread.

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2545998&SiteID=1

     

    Moreover, please retrieve it by the key word "interface abstract class" in this forum and the
    relating forum.

    A lot of profitable information is found.

    Sunday, December 23, 2007 3:58 AM
  • Hi,

     

    Thnx for giving info.Actually iam looking for projct development point of view..In whihc cases i do go 4 developing abstract classes  other interfaces

    Monday, December 24, 2007 9:34 AM