What are the differences between an interface and an abstract class.

 Posted by Ddd on 1/17/2011 | Category: .NET Framework Interview questions | Views: 4117 | Points: 40

Both interface and an abstract class cannot be instantiated and are implemented
by inheriting them in other classes.

The differences between them are:

a)All members are public by default.
b)They cannot contain fields.
c)No coding of the methods or the properties is allowed.
d)They do not provide implementation.
e)Interfaces support multiple inheritance
f)abstract keyword is not there before the interface or its members names.

Abstract classes
a)All members are private by default. We can put modifiers like
public, protected before the abstract class members.
b)They can contain fields.
c) coding of the methods or the properties is allowed.(nonabstract)
we can also declare abstract methods(methods with no coding) and only
the declaration
d)They can provide implementation. An abstract class can implement an
e)Abstract classes support single inherritance
g)abstract keyword is required before their names and also before the
abstract methods or properties.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Ck.kislay on: 1/18/2011 | Points: 10
If Abstracat class has only abstract methods then in that case Abstract class and Interface have adjactly similar behaviour.

Posted by: Ddd on: 1/18/2011 | Points: 10
interface strictly contains abstract methods while the abstract class can have abstract as well
as nonabstract methods.

Login to post response