class 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 explicitly specify a direct base class, its direct base class is implicitly object. end example] Paragraph 21 The direct base class of a class type must be at least as accessible as the class type itself (§10.5.4). 2 For example, it is a compile-time error for a public class to derive from a private or internal class. Paragraph 31 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. Paragraph 41 The base classes of a class are the direct base class and its base classes. 2 In other words, the set of base classes is the transitive closure of the direct base class relationship. [Note: Referring to the example above, the base classes of B are A and object. end note] Paragraph 51 Except for class object, every class has exactly one direct base class. 2 The object class has no direct base class and is the ultimate base class of all other classes. Paragraph 61 When a class B derives from a class A, it is a compile-time error for A to depend on B. 2 A class directly depends on its direct base class (if any) and directly depends on the class within which it is immediately nested (if any). 3 Given this definition, the complete set of classes upon which a class depends is the transitive closure of the directly depends on relationship. [Example: The example
class A: B {} class B: C {} class C: A {}is in error because the classes circularly depend on themselves. Likewise, the example
class 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 (its immediately enclosing class), which circularly depends on A. end example] Paragraph 71 Note that a class does not depend on the classes that are nested within it. [Example: In the example
class A { class B: A {} }B depends on A (because A is both its direct base class and its immediately enclosing class), but A does not depend on B (since B is neither a base class nor an enclosing class of A). Thus, the example is valid. end example] Paragraph 81 It is not possible to derive from a sealed class. [Example: In the example
sealed 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]
| |
Jagger Software Ltd | |
Company # 4070126 | |
VAT # 762 5213 42 |