what is a sealed class? [Resolved]

Posted by Rajendra.prasad under C# on 3/22/2010 | Views : 18372 | Status : [Member] | Replies : 3
what is a sealed class. can we create an object of a sealed class.

regards,
Rajendra




Responses

Posted by: Kalyankumaarm on: 3/22/2010 [Member] Starter

Up
0
Down

Resolved
if we prevent one class from being inherited.we need to define as sealed class.
yes we can create objects for sealed class.

example using C#

using System;

class MyClass1

{

static void Main(string[] args)

{

MySealedClass sealedCls = new MySealedClass();

int total = sealedCls.Add(4, 5);

Console.WriteLine("Total = " + total.ToString());

}

}

// Sealed class

sealed class MySealedClass

{

public int Add(int x, int y)

{

return x + y;

}

}




Rajendra.prasad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 3/23/2010 [Member] Bronze

Up
0
Down

Resolved
when a class defined as sealed its not possible to inherit its class and properties to the inherited class.Its also applicable to the class
properties.Even class defined as public its banned to inherit the class.

example

using System;

class Class1

{

static void Main(string[] args)

{

SealedClass sealedCls = new SealedClass();

int total = sealedCls.Add(4, 5);

Console.WriteLine("Total = " + total.ToString());

}

}

// Sealed class

sealed class SealedClass

{

public int Add(int x, int y)

{

return x + y;

}

}





Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Rajendra.prasad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 3/23/2010 [Member] Starter

Up
0
Down
Hi,
check the following link to understand about Sealed class

http://www.c-sharpcorner.com/UploadFile/mahesh/SealedClasses11142005063733AM/SealedClasses.aspx

Syed Shakeer Hussain

Rajendra.prasad, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response