13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 17 Classes17. ClassesA class is a data structure that may contain data members (constants and fields), function members (methods,properties, events, indexers, operators, instance constructors, destructors, and static constructors), and nestedtypes. Class types support inheritance, a mechanism whereby a derived class can extend and specialize a baseclass.17.1 Class declarationsA class-declaration is a type-declaration (§16.5) that declares a new class.class-declaration:attributes opt class-modifiers opt class identifier class-base opt class-body ; optA class-declaration consists of an optional set of attributes (§24), followed by an optional set of class-modifiers(§17.1.1), followed by the keyword class and an identifier that names the class, followed by an optional classbasespecification (§17.1.2), followed by a class-body (§17.1.3), optionally followed by a semicolon.17.1.1 Class modifiersA class-declaration may optionally include a sequence of class modifiers:class-modifiers:class-modifierclass-modifiers class-modifierclass-modifier:newpublicprotectedinternalprivateabstractsealedIt is a compile-time error for the same modifier to appear multiple times in a class declaration.The new modifier is permitted on nested classes. It specifies that the class hides an inherited member by the samename, as described in §10.2.2. It is a compile-time error for the new modifier to appear on a class declaration thatis not a nested class declaration.The public, protected, internal, and private modifiers control the accessibility of the class. Dependingon the context in which the class declaration occurs, some of these modifiers may not be permitted (§10.5.1).The abstract and sealed modifiers are discussed in the following sections.17.1.1.1 Abstract classesThe abstract modifier is used to indicate that a class is incomplete and that it is intended to be used only as abase class. An abstract class differs from a non-abstract class in the following ways:• An abstract class cannot be instantiated directly, and it is a compile-time error to use the new operator on anabstract class. While it is possible to have variables and values whose compile-time types are abstract, suchvariables and values will necessarily either be null or contain references to instances of non-abstract classesderived from the abstract types.• An abstract class is permitted (but not required) to contain abstract members.209

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

Saved successfully!

Ooh no, something went wrong!