Monday, June 28, 2010

Difference Between abstract Class and interface

Difference Between abstract Class and interface
Abstract class having method declaration as well as method method definition whereas interface having method declaration only.

2>Abstract class are known as partial abstract class whereas interface is known as fully abstract class.

3>Abstract class features we have to inherit to the child class whereas interface features we have to implement in the child classes.

4>Abstract class support access specifiers whereas interface doesn't support access specifiers.

5>Abstract class have normal variable as well as constant variable whereas interface have only constant variables.

6>We can write constructor in abstract class whereas we can't write constructor in interface.
• Interface contains methods that must be abstract; abstract class may contain concrete methods.
• Interface contains variables that must be static and final; abstract class may contain non-final and final variables.
• Interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces.
• Interface is absolutely abstract; abstract class can be invoked if a main() exists.
• Interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces.
• Members in an interface are public by default; abstract class may contain non-public members.
• Interface is used to "implements"; whereas abstract class is used to "extends".
• Interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance.
[b]Abstract[/b]
It can be used with properties,classes,method,indexers and event.

An Abstract class can not be instantiated.
An Abstract class contains methods and accessors.
An Abstract class can not inherited.

[b]Interface[/b]

It contains only signature of delegates,method and events.
All members are public and abstract.
Interface is reference type.

[b]Sealed[/b]
It is applied for classes,methods and properties.

A Sealed class can not be inherited.
It throws an error if you sealed class as a base class

[b]Static[/b]

It is used for classes, methods,fields, properties, events, operators, and constructors.

All the members in the static class must be static.

No comments:

Post a Comment