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.

Chapter 17 ClassesThe direct base class of a class type must be at least as accessible as the class type itself (§10.5.4). For example, itis a compile-time error for a public class to derive from a private or internal class.The direct base class of a class type must not be any of the following types: System.Array,System.Delegate, System.Enum, or System.ValueType.The base classes of a class are the direct base class and its base classes. In other words, the set of base classes isthe transitive closure of the direct base class relationship. [Note: Referring to the example above, the base classesof B are A and object. end note]Except for class object, every class has exactly one direct base class. The object class has no direct base classand is the ultimate base class of all other classes.When a class B derives from a class A, it is a compile-time error for A to depend on B. A class directly depends onits direct base class (if any) and directly depends on the class within which it is immediately nested (if any).Given this definition, the complete set of classes upon which a class depends is the transitive closure of thedirectly depends on relationship.[Example: The exampleclass A: B {}class B: C {}class C: A {}is in error because the classes circularly depend on themselves. Likewise, the exampleclass A: B.C {}class B: A{public class C {}}results in a compile-time error because A depends on B.C (its direct base class), which depends on B (itsimmediately enclosing class), which circularly depends on A. end example]A class does not depend on the classes that are nested within it. [Example: In the exampleclass A{class B: A {}}B depends on A (because A is both its direct base class and its immediately enclosing class), but A does notdepend on B (since B is neither a base class nor an enclosing class of A). Thus, the example is valid. end example]It is not possible to derive from a sealed class. [Example: In the examplesealed class A {}class B: A {} // Error, cannot derive from a sealed classclass B results in a compile-time error because it attempts to derive from the sealed class A. end example]17.1.2.2 Interface implementationsA class-base specification may include a list of interface types, in which case the class is said to implement thegiven interface types. Interface implementations are discussed further in §20.4.17.1.3 Class bodyThe class-body of a class defines the members of that class.class-body:{ class-member-declarations opt }211

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

Saved successfully!

Ooh no, something went wrong!