Advertise with us

difference between abstract class and sealed class.

Posted by  Manoj Bhatt
C#  .NET  OOPS  Class 
 1359  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.
  1. Re: difference between abstract class and sealed class.

    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

      Modified On Apr-11-2018 12:25:07 AM