nikhil kansal
What’s the difference between an interface and abstract class?
By nikhil kansal in ASP.NET on Jul 14 2006
  • ranveer singh
    Jun, 2012 19

    abstract class contain the data member and member funtion.

    • 1
  • Oceanpass
    Dec, 2011 17

    1. Abstract classes can have implementations for some of its members, but the interface can't have implementation for any of its members. 2.Interfaces cannot have fields where as an abstract class can have fields. 3. An interface can inherit from another interface only and cannot inherit from an abstract class, where as an abstract class can inherit from another abstract class or another interface. 4. A class can inherit from multiple interfaces at the same time, where as a class cannot inherit from multiple classes at the same time. 5. Abstract can have access modifiers where as interface members cannot have access modifiers.

    • 0
  • Nicks
    Apr, 2011 13

    Interface can not have scope modifiers while Abstract classes can have scope modifiers

    • 0
  • vaishnavi ranganathan
    Oct, 2010 10

    Interface is the syntotical contract that all the derived class should follow. It contains methods,events and properties which are known as interface members. It is to be noted that,interface should contain only declaration of members. classes and structures can implement interface members. interface enable multiple inheritance. Abstract class can be inherited we cannot declare abstract method outside abstract class abstract class cannot be declared sealed. abstract method is a method without any body.

    • 0
  • saeed shirzadian
    Jul, 2010 21

    First, no method and property can't implementation in the interface but in abstract class you can implementation such of method or property Second, interface has any constructor but abstract class can has. third, you can inherits of some interface but you can inherits of one class or abstract class

    • 0
  • Gaurav Kumar Arora
    Jul, 2010 17

    I am bit late here most of points are considered above but I want to give my views as : 1. Abstract classes contain constructor While interface do not 2. Default constructor modifier is Protected of Abstract classes 3. We can apply constructor chaining with Abstract classes

    • 0
  • Ankit Bhadana
    Jun, 2010 22

    There are two basic difference between Abstract class and Interface: 1. Abstract class provides 0 to 100% generalization while Interface provides 100% generalization.2. Abstract class provides generalization and specialization both but Interface provides only Generalization

    • 0
  • vijay kumar
    May, 2010 19

    Interface: In an interface is a class and all methods are abstract, No need access modifier, default public. Abstract: In an interface is a class and all methods are concrete, may have access modifier

    • 0
  • Reva Sahu
    Dec, 2009 31

    Interfaces provide a form of multiple inheritance. A class can extend only one other class. Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc. A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast.

    • 0
  • Thaker Kandarp
    Nov, 2008 8

    Interface are similar to abstraction classes. However, interfaces 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 an implementation. In contrast, the abstract classes might contain a method that has a body.

    • 0
  • nitesh kumar
    Aug, 2008 1

    1).Interface have only signature. whereas Abstract class have signature and definition both r allow. 2). Interface have not allow modifier access. whereas Abstract class are allowed modifier access. 3).Thurogh the Interface we can create the Multiple Inheritance whereas Abstract class are not allow the Multiple Inheritance. 4).Interface is slower compare Abstract class.

    • 0
  • nagaraju rekulapelli
    Jul, 2008 13

    Interface:- 1. Interfaces are used to declaring functionality. 2. By default all interface methods are public. 3. In class you can implement the interface method, but can’t implement the body in Interface method. Abstract:- 1. Abstract will allow you to set the access specifier. Ex:- (private,public, protected, internal). 2. Abstract will allow you to implement the body in abstract methods. 3. You can inherit the abstract methods in classes.

    • 0
  • wang heaven
    Jul, 2008 2

    in an interface class, all the methods are abstract, these is no implementation,and no accessbility modifiers are allowed, in an abstract class, some of the methods can be concrete,an abstract class may have some accessbility modifiers.

    • 0
  • sanjeev singh
    Jun, 2008 9

    An abstract class may contain complete or incomplete methods. Interfaces can contain only the signature of a method but no body. Thus an abstract class can implement methods but an interface can not implement methods. · An abstract class can contain fields, constructors, or destructors and implement properties. An interface can not contain fields, constructors, or destructors and it has only the property's signature but no implementation. · An abstract class cannot support multiple inheritance, but an interface can support multiple inheritance. Thus a class may inherit several interfaces but only one abstract class. · A class implementing an interface has to implement all the methods of the interface, but the same is not required in the case of an abstract Class. · Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces.

    • 0
  • Mohd Nasar
    Mar, 2008 12

    In a interface class, all methods are abstract without implementation where as in an abstract class some methods we can define concrete. In interface, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers. Interface and abstract class are basically a set of rules which u have to follow in case u r using them(inheriting them).

    • 0
  • Jan, 2008 23

    Interface only implementaion ,it is fully abstact classes.

    Abstract is not implemented class,it is only inherited class

    • 0
  • Shaik Hanumantha Rao
    Jun, 2007 4

    An abstract class may contain complete or incomplete methods. Interfaces can contain only the signature of a method but no body. Thus an abstract class can implement methods but an interface can not implement methods.

    An abstract class can contain fields, constructors, or destructors and implement properties. An interface can not contain fields, constructors, or destructors and it has only the property’s signature but no implementation.

    An abstract class cannot support multiple inheritance, but an interface can support multiple inheritance. Thus a class may inherit several interfaces but only one abstract class.

    A class implementing an interface has to implement all the methods of the interface, but the same is not required in the case of an abstract Class.

    Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces.

    Abstract classes are faster than interfaces.

    • 0
  • anil kumar
    Jun, 2007 2

    interface just declaration.it provide standared for programming.it has no code.on the other hand abstaract class is one which can not make object.it is always inherited.

    1. public abstarct class clscon
    2. {
    3. protected sqlconnection con= new sqlconnection()
    4. public clscon()
    5. {
    6. con.connectionstring=configurationmanager.
    7. connectionstring("cn").connectionstring;
    8. }
    9. }//this is abstract class

    interface

    1. public interface intemp
    2. {
    3. get;
    4. set;
    5. }

    • 0
  • May, 2007 16

    There are basically three things to understand about interfaces and abstract classes: 1. Interfaces declare the methods a class must implement, but don't contain code. 2. Abstract classes may contain a mix of abstract and implemented methods. The abstract methods must be overridden in descendant classes.

    • 0
  • Gurjinder Singh Brar
    Jan, 2007 25

    • An interface cannot provide any code; just the signature means all methods must be abstract. But an abstract class can provide complete, default code and/or just the details but at least at least one method must be abstract.
    • A class may inherit several interfaces. But a class may inherit only one abstract class.
    • If the various implementations only share method signatures then it is better to use Interface. If the various implementations are of the same kind and use common behavior or status then abstract class is better to use.
    • If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. But if we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.

    • 0
  • sampathnsb
    Aug, 2006 28

    in interfaces we can only define methods. But we cant implemented those methods in interfaces itself. interfaces allow us to have multiple inheritance.

    in abstract classes we can define method and if we want we can implement those methods in abstact class. we cant instantiate from abstract classes.

    • 0
  • Aug, 2006 5

    What is an Interface?

    An interface is a contract, a specification that concrete classes MUST follow. It defines method signatures but cannot have any implementations; the latter must be provided by the classes that implement the interface.

    C# differs from C++ in this regard because C++ lacks native language support for interfaces. As a C++ programmers you have to create an interface by defining an abstract class with pure virtual methods.

    what is an abstract class?

    An Abstract class lets you define some behaviors and force your subclasses to provide others.
    For example, if you have an application framework, an abstract class may provide default services such as event and message handling. Those services allow your application to plug in to your application framework. However, there is some application-specific functionality that only your application can perform. So instead of trying to define these behaviors, the abstract class can declare abstract methods.

    Differences between Interfaces and Abstract classes Which we use ?

    1. multiple inheritance
      A class may implement several interfaces but can only extend one abstract class.

    2. default implementation
      An interface cannot provide any code at all, much less default code. An abstract class can provide complete code, default code, and/or just stubs that have to be overridden.

    3. adding functionality
      If you add a new method to an interface, you must track down all implementations of that interface in the universe and provide them with a concrete implementation of that method.

      If you add a new method to an abstract class, you have the option of providing a default implementation of it. Then all existing code will continue to work without change.

    4. is-a vs -able or can-do
      Interfaces are often used to describe the abilities of a class, not its central identity, e.g. an Automobile class might implement the Recyclable interface, which could apply to many otherwise totally unrelated objects.

      An abstract class defines the core identity of its descendants.

    • 0
  • Aug, 2006 4

    when u want to go for inheritance in so many derived classes but the methods implementations are different for different derived classes then u will make the class as abstract or interface. When all the method's implementations are based on derived class u will go for interface and if few implementations are common and remaining depends on derived class u will go for abstract class where u can have defined as well as declared methods also. Note: abstract and interface classes are used when their methods are mandatory for derived classes and are not optional. They put restriction on derived classes that they cannot skip those methods withoud having them in it. bye -Ram Nath Nishad New Horizons India Ltd, N-101,Manipal Center, Bangalore, India

    • 0
  • Jul, 2006 14

    In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS