Sealed Class in .NET …………….

If we defined a class with a keyword "sealed" then we cannot create or we 
Cannot derive a child class it will give compiler error. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sealed_Class
{
    sealed class car
    {
        public void display()
        {
            Console.WriteLine("In display of Car");
        }
    }

    class vehicle : car
    {
        public void display()
        {
            Console.WriteLine("In display of Vehicle");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            car obj = new car();
            obj.display();
            Console.Read();
        }
    }
}
OUTPUT :- 'Sealed_Class.vehicle': cannot derive from sealed type 'Sealed_Class.car'.

SHARE THE KNOWLEDGE


  

Advertisements

About Dinesh

I am engineering student........ I am selected in Microsoft Student Partner as MSP............

Posted on August 30, 2011, in .NET, C#, Knowledge. Bookmark the permalink. Leave a comment.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: