A class try a document structure that can contain investigation people (constants and you will areas), means professionals (actions, features, events, indexers, workers, particularly constructors, finalizers, and you may static constructors), and you will nested types.
14.dos.step 1 Standard
A category_statement includes an optional group of attributes (§21), followed closely by an optional selection of class_modifiers (§14.2.2), followed closely by a recommended partial modifier (§14.dos.7), with the newest search term category and you will an identifier you to definitely brands the brand new group, accompanied by a recommended type of_parameter_record (§14.dos.3), accompanied by an elective group_feet specs (§14.dos.4), followed by an optional number of variety of_parameter_constraints_conditions (§14.2.5), followed closely by a course_body (§14.2.6), optionally followed by an excellent semicolon.
A category eter_listing is a simple class report. Additionally, any category nested in to the a general group statement or a general struct statement is alone a general category declaration, as the method of objections with the who has sort of will be given to would a built sort of.
14.2.dos.step 1 Standard
The newest modifier was permitted to your nested classes. They determine the group covers an inherited representative of the exact same identity, while the demonstrated when you look at the §14.step 3.5. It’s an accumulate-big date mistake into the newest modifier to look toward a course report that’s not a great nested group statement.
Individuals , protected , interior , and private modifiers handle the brand new use of of your own classification. According to the perspective the spot where the class statement happens, any of these modifiers might not be allowed (§eight.5.2).
When a limited kind of report (§fourteen.2.7) boasts an accessibility requirements (through the social , protected , internal , and private modifiers), one requirements should accept any kind of parts that come with a keen use of specs. In the event the zero part of a limited type has an accessibility specs, the kind is offered appropriate default accessibility (§eight.5.2).
fourteen.dos.2.dos Abstract categories
This new abstract modifier can be used to suggest one a class is actually partial and that it is intended to be made use of only since a base classification. An abstract class differs from a non-abstract group regarding following ways:
- A conceptual category can’t be instantiated individually, and it is an assemble-go out mistake to make use of the new user into the a conceptual category. While it’s you are able to for details and you can beliefs whoever attain-big date versions is conceptual, such as for example details and you can beliefs usually necessarily be either null otherwise incorporate sources so you can instances of low-conceptual classes derived from the fresh abstract sizes.
- An abstract class is actually let (but not required) so you’re able to have abstract people.
- A conceptual class cannot be shut.
Whenever a low-abstract classification comes from a conceptual classification, new non-conceptual class shall tend to be real implementations of all of the passed on conceptual participants, and therefore overriding the individuals conceptual professionals.
the latest abstract group A beneficial raises a conceptual method F . Class B raises an extra method Grams , but whilst does not offer an utilization of F , B should additionally be stated abstract. Class C overrides F while offering an actual execution. Since there are no conceptual members in the C , C was allowed (but not necessary) as non-conceptual. end analogy
If one or maybe more elements of a partial kind of report (§14.dos.7) away from a class include the conceptual modifier, the category are conceptual. If you don’t, the class is low-abstract.
fourteen.2.dos.step three Close groups
The fresh close modifier is utilized to eliminate derivation out of a course. An amass-go out mistake happen if a shut category is actually given since the foot category of various other class.
Note: The newest closed modifier is especially always prevent unintended derivation, but it also permits particular work with-go out optimizations. In particular, swapfinder because the a close classification may never have one derived classes, you can change virtual mode user invocations toward shut category hours towards non-virtual invocations. prevent mention