December 16, 2012

SEALED CLASS


SEALED CLASS

When you want to restrict your classes from being inherited by others you can create the class as sealed class. 

                SEALED is a keyword used to define class as sealed class.

A sealed class cannot be inherited by other class. Sealed Access modifier can be used with method , classes and properties.               

                Sealed classes can not be used as base class . hence they can not be considered as Abstract class.

Eg:
sealed public class SealedClassDemo
{
        public SealedClassDemo()
       {
              //
              // TODO: Add constructor logic here
              //
       }

     public int Square(int no)
     {
         return no * no;
     }
}

 In this example class is declared as Sealed.

No comments:

Post a Comment