Breaking News

Editors Picks

Tuesday, June 21, 2011

sealed keyword c sharp


sealed 

The sealed modifier can be applied to classes, instance methods and properties. A sealed class cannot be inherited. A sealed method overrides a method in a base class, but itself cannot be overridden further in any derived class. When applied to a method or property, the sealed modifier must always be used with override 

It is an error to use a sealed class as a base class or to use the abstract modifier with a sealed class.
Structs are implicitly sealed; therefore, they cannot be inherited
Example


sealed class SealedClass
{
    public int x;
    public int y;
}
 
class SealedTest2
{
    static void Main()
    {
        SealedClass sc = new SealedClass();
        sc.x = 110;
        sc.y = 150;
        Console.WriteLine("x = {0}, y = {1}", sc.x, sc.y);
    }
}
// Output: x = 110, y = 150

No comments :

Post a Comment

Contact Us

Name

Email *

Message *