13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATION• An abstract class cannot be sealed.When a non-abstract class is derived from an abstract class, the non-abstract class must include actualimplementations of all inherited abstract members, thereby overriding those abstract members. [Example: In theexampleabstract 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 itdoesn’t provide an implementation of F, B must also be declared abstract. Class C overrides F and provides anactual implementation. Since there are no abstract members in C, C is permitted (but not required) to be nonabstract.end example]17.1.1.2 Sealed classesThe sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class isspecified as the base class of another class.A sealed class cannot also be an abstract class.[Note: The sealed modifier is primarily used to prevent unintended derivation, but it also enables certain runtimeoptimizations. In particular, because a sealed class is known to never have any derived classes, it is possibleto transform virtual function member invocations on sealed class instances into non-virtual invocations. end note]17.1.2 Class base specificationA class declaration may include a class-base specification, which defines the direct base class of the class and theinterfaces (§20) implemented by the class.class-base:: class-type: interface-type-list: class-type , interface-type-listinterface-type-list:interface-typeinterface-type-list , interface-type17.1.2.1 Base classesWhen a class-type is included in the class-base, it specifies the direct base class of the class being declared. If aclass declaration has no class-base, or if the class-base lists only interface types, the direct base class is assumedto be object. A class inherits members from its direct base class, as described in §17.2.1.[Example: In the exampleclass A {}class B: A {}class A is said to be the direct base class of B, and B is said to be derived from A. Since A does not explicitlyspecify a direct base class, its direct base class is implicitly object. end example]210

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!