tags:

views:

38

answers:

3

If I seal a class are all overriden members implicitly sealed or do I have to seal each overriden member explicitly?

public sealed ClassA : ClassB
{

// Is this implicitly sealed or do I have to explicitly seal
public override void Method1()
{}

}

TIA.

Klaus

+3  A: 

From the MSDN

A sealed class cannot be inherited. It is an error to use a sealed class as a base class. Use the sealed modifier in a class declaration to prevent inheritance of the class.

Given that you can't inherit from the class there is no need to seal individual members. Indeed it makes no sense.

I've found a tutorial on sealed classes and methods which might provide further clarification.

ChrisF
+1  A: 

Sealing a class means that you cannot inherit from it. It is meaningless to seal members of a sealed class.

Oded
A: 

You seal the whole ClassA.

It means, You can inherit from and override ClassB definition, but not ClassA.

Rafal Ziolkowski