X hits on this document

957 views

0 shares

0 downloads

0 comments

240 / 396

Chapter ‎18   Unsafe code

the F method in B hides the virtual F method inherited from A. Since the new F in B has private access, its scope only includes the class body of B and does not extend to C. Therefore, the declaration of F in C is permitted to override the F inherited from A.

10.5.5 Sealed methods

When an instance method declaration includes a sealed modifier, that method is said to be a sealed method. If an instance method declaration includes the  sealed modifier, it must also include the override modifier. Use of the sealed modifier prevents a derived class from further overriding the method.

The example

using System;

class A { public virtual void F() { Console.WriteLine("A.F"); }

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.

10.5.6 Abstract methods

When an instance method declaration includes an abstract modifier, that method is said to be an abstract method. Although an abstract method is implicitly also a virtual method, it cannot have the modifier virtual.

An abstract method declaration introduces a new virtual method but does not provide an implementation of that method. Instead, non-abstract derived classes are required to provide their own implementation by overriding that method. Because an abstract method provides no actual implementation, the method-body of an abstract method simply consists of a semicolon.

Abstract method declarations are only permitted in abstract classes (§‎10.1.1.1).

In the example

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.227

Document info
Document views957
Page views957
Page last viewedThu Dec 08 12:27:33 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments