Home > DeveloperSection > Forums > difference between abstract class and sealed class.
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    January-15-2016 10:55 PM

 C# C#  .NET  OOPS  Class 
Ratings:


 1 Reply(s)
 225  View(s)
Rate this:
Hi Everyone,
Can any one explain about abstract class and sealed class with a demo. What is the difference between this two classes.
Thanks in advance.


Anupam Mishra

Total Post:135

Points:949
Posted on    January-17-2016 10:33 PM

Here, i am explaining about abstract class:
The abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.

An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. For example, a class library may define an abstract class that is used as a parameter to many of its functions, and require programmers using that library to provide their own implementation of the class by creating a derived class.

Abstract classes may also define abstract methods. This is accomplished by adding the keyword abstract before the return type of the method. For more details: Please click  this link

Here, i am explaining about sealed class:
The sealed keyword enables you to prevent the inheritance of a class or certain class members that were previously marked virtual.

A sealed class cannot be used as a base class. For this reason, it cannot also be an abstract class. Sealed classes prevent derivation. Because they can never be used as a base class, some run-time optimizations can make calling sealed class members slightly faster.

A method, indexer, property, or event, on a derived class that is overriding a virtual member of the base class can declare that member as sealed. This negates the virtual aspect of the member for any further derived class. This is accomplished by putting the sealed keyword before the override keyword in the class member declaration.  For more details Click Here



Don't want to miss updates? Please click the below button!

Follow MindStick