17.5.5 Sealed methods
来源:互联网 发布:汉朝军衔知乎 编辑:程序博客网 时间:2024/05/18 01:51
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]
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]
- 17.5.5 Sealed methods
- 17.5.5 Sealed methods
- sealed
- sealed
- sealed
- Sealed
- sealed
- 17.5 Methods
- 17.5 Methods
- 5、Methods
- scala 随笔(5) sealed 解析
- 17.5.3 Virtual methods
- 17.5.4 Override methods
- 17.5.6 Abstract methods
- 17.5.3 Virtual methods
- 17.5.4 Override methods
- 17.5.6 Abstract methods
- METHODS
- 17.5 Methods
- 17.5.1 Method parameters
- 17.5.2 Static and instance methods
- 17.5.3 Virtual methods
- 17.5.4 Override methods
- 17.5.5 Sealed methods
- 使用Arcgis Engine开发时发现.Net help中有些小错误
- Java Bean 与 EJB的区别
- 17.5.6 Abstract methods
- 17.5.8 Method body
- 17.5.9 Method overloading
- web2.0人民的力量?
- 《The Art of Computer Programming》的PREFACE
- 开发笔记-NAND Flash Addressing Mode