X hits on this document





210 / 396

Chapter ‎18   Unsafe code

derived from the abstract types.

An abstract class is permitted (but not required) to contain abstract members.

An abstract class cannot be sealed.

When a non-abstract class is derived from an abstract class, the non-abstract class must include actual implementations of all inherited abstract members, thereby overriding those abstract members. In the example

abstract class A { public abstract void F(); }

abstract class B: A { public void G() {} }

class C: B { public override void F() { // actual implementation of F } }

the abstract class A introduces an abstract method F. Class B introduces an additional method G, but since it doesn’t provide an implementation of F, B must also be declared abstract. Class C overrides F and provides an actual implementation. Since there are no abstract members in C, C is permitted (but not required) to be non-abstract. Sealed classes

The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class.

A sealed class cannot also be an abstract class.

The sealed modifier is primarily used to prevent unintended derivation, but it also enables certain run-time optimizations. In particular, because a sealed class is known to never have any derived classes, it is possible to transform virtual function member invocations on sealed class instances into non-virtual invocations.

10.1.2 Class base specification

A class declaration may include a class-base specification, which defines the direct base class of the class and the interfaces (‎13) implemented by the class.

class-base: :   class-type :   interface-type-list :   class-type   ,   interface-type-list

interface-type-list: interface-type interface-type-list   ,   interface-type Base classes

When a class-type is included in the class-base, it specifies the direct base class of the class being declared. If a class declaration has no class-base, or if the class-base lists only interface types, the direct base class is assumed to be object. A class inherits members from its direct base class, as described in §‎10.2.1.

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

Document info
Document views626
Page views626
Page last viewedWed Oct 26 16:13:22 UTC 2016