Pages

Men

rh

10/19/2013

Difference between Abstract Class and Sealed Class in C#

Abstract Class:-
  • A Class which contains one or more abstract functions  is known as Abstract Class.
  • An Abstract Class can contains Non - Abstract and Abstract functions.
  • Creating a new class from an abstract class is compolsory to consume it.
  • An Abstract Class can not be instantiated directly, we need to create a object for derived class to consume an Abstract class.
  • Use Abstract Keyword to make a class as a Abstract.
  • An Abstrac class  can not be the bottom most class with the Inheritance hierarchy.
  • An Abstract Class should be used as a base class only.


Sealed Class:-
  •  A Class from which is not possible to derive a new class is known as Sealed Class.
  •  A Sealed Class can contains Non - Abstract  functions and can not contain Abstract and Virtual functions.
  • It is not possible to create a new class from the sealed class.
  • We should not create a an object for sealed class only to consume it.
  • Use Sealed Keyword to make a class as a Sealed.
  • Sealed class should not be the bottom, most class with in the Inheritance hierarchy.
  • A Sealed class can not be used as  base class.

No comments :

Post a Comment