17.5.5 Sealed methods

王朝other·作者佚名  2006-05-09
窄屏简体版  字體: |||超大  

When an instance method declaration includes a sealed modifier, that method

is said to be a sealed method. A

sealed method overrides an inherited virtual method with the same

signature. An override method can also be

marked with the sealed modifier. Use of this modifier prevents a derived

class from further overriding the

method.

[Example: The example

using System;

class A

{

public virtual void F() {

Console.WriteLine("A.F");

}

Chapter 17 Classes

237

public virtual void G() {

Console.WriteLine("A.G");

}

}

class B: A

{

sealed override public void F() {

Console.WriteLine("B.F");

}

override public void G() {

Console.WriteLine("B.G");

}

}

class C: B

{

override public void G() {

Console.WriteLine("C.G");

}

}

the class B provides two override methods: an F method that has the sealed

modifier and a G method that does

not. B?s use of the sealed modifier prevents C from further overriding F.

end example]

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航