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 same class, and two methods declared in the same class may not have signatures that differ solely by refand out.• The signature of an instance constructor must differ from the signatures of all other instance constructorsdeclared in the same class, and two constructors declared in the same class may not have signatures thatdiffer solely by ref and out.• The signature of an indexer must differ from the signatures of all other indexers declared in the same class.• The signature of an operator must differ from the signatures of all other operators declared in the same class.The inherited members of a class (§17.2.1) are not part of the declaration space of a class. [Note: Thus, a derivedclass is allowed to declare a member with the same name or signature as an inherited member (which in effecthides the inherited member). end note]17.2.1 InheritanceA class inherits the members of its direct base class. Inheritance means that a class implicitly contains allmembers of its direct base class, except for the instance constructors, destructors, and static constructors of thebase class. Some important aspects of inheritance are:• Inheritance is transitive. If C is derived from B, and B is derived from A, then C inherits the membersdeclared in B as well as the members declared in A.• A derived class extends its direct base class. A derived class can add new members to those it inherits, but itcannot remove the definition of an inherited member.• Instance constructors, destructors, and static constructors are not inherited, but all other members are,regardless of their declared accessibility (§10.5). However, depending on their declared accessibility,inherited members might not be accessible in a derived class.• A derived class can hide (§10.7.1.2) inherited members by declaring new members with the same name orsignature. However, hiding an inherited member does not remove that member—it merely makes thatmember inaccessible in the derived class.• An instance of a class contains a set of all instance fields declared in the class and its base classes, and animplicit conversion (§13.1.4) exists from a derived class type to any of its base class types. Thus, a referenceto an instance of some derived class can be treated as a reference to an instance of any of its base classes.• A class can declare virtual methods, properties, and indexers, and derived classes can override theimplementation of these function members. This enables classes to exhibit polymorphic behavior wherein theactions performed by a function member invocation varies depending on the run-time type of the instancethrough which that function member is invoked.17.2.2 The new modifierA class-member-declaration is permitted to declare a member with the same name or signature as an inheritedmember. When this occurs, the derived class member is said to hide the base class member. Hiding an inheritedmember is not considered an error, but it does cause the compiler to issue a warning. To suppress the warning,the declaration of the derived class member can include a new modifier to indicate that the derived member isintended to hide the base member. This topic is discussed further in §10.7.1.2.If a new modifier is included in a declaration that doesn’t hide an inherited member, a warning to that effect isissued. This warning is suppressed by removing the new modifier.17.2.3 Access modifiersA class-member-declaration can have any one of the five possible kinds of declared accessibility (§10.5.1):public, protected internal, protected, internal, or private. Except for the protected internalcombination, it is a compile-time error to specify more than one access modifier. When a class-memberdeclarationdoes not include any access modifiers, private is assumed.213

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

Saved successfully!

Ooh no, something went wrong!