Showing posts with label ifferences between interface and an abstract class. Show all posts
Showing posts with label ifferences between interface and an abstract class. Show all posts

Tuesday 17 January 2012

Differences between interface and an abstract class

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


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

The differences between them are:

Interfaces--

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
interface
e)Abstract classes support single inherritance
g)abstract keyword is required before their names and also before the
abstract methods or properties.