The Class-ID paragraph indicates that this Identification Division is introducing a class definition and specifies the name
that identifies the class and assigns class attributes to the class.
General Format
Directives
- In addition to the Compiler directives which provide flagging and modify the reserved word list, the following directives
may impact either the syntax or the semantics described in this section.
- ACTUAL-PARAMS - specifies the parameters to be used in the creation of a class from a parameterized class or interface.
- ILSOURCE - specifies a file that contains another program to form part of the current .NET assembly. This may include further
components of a partial class .
Syntax Rules
- Literal-1 must be an alphanumeric literal and must not be a figurative constant.
- Type-specifier-1 must not be the name of the class declared by this class definition.
- Type-specifier-1 must not inherit from class-name-1 directly or indirectly.
- Type-specifier-1 must not be the name of a class defined with the FINAL clause.
- Type-specifier-1 cannot be repeated when you compile a program for .NET. In other words, multiple inheritance is not allowed.
- Type-specifier-2 must not refer to the interface.
- A given class name must not appear more than once in an INHERITS clause.
- If two or more different methods with the same name are inherited, none of them may be specified with the FINAL clause. If
the same method is inherited from one superclass through two or more intermediate superclasses, it may be specified with the
FINAL clause.
- If a given method-name is inherited from more than one inherited class, then, if the prototypes for these methods are such
that to define a method with the same interface as any one of them in this class would prevent this class from conforming
to all the inherited classes, then a method with the same method-name must be declared in this class. This method must satisfy
syntax rule 9 in the topic
The Method-ID Paragraph.
Note: If class A inherits method M from two classes, B and C, and the method interface for M is not identical in classes B and C
(say M in B returns an object of class X, and M in C returns an object of an unrelated class Y), then the inheritance is invalid,
unless a valid method override of M is defined in class A that resolves the method interface conformance problem. It is not
always possible to do so (in which case the inheritance is not valid), but there are some cases in which it can be done. For
example, if it is possible to define Z as a class that inherits X and Y, then a method override for M could be specified in
class A, returning an object of class Z.
- Parameter-name-1 must be a name specified in a class-specifier or an interface-specifier in the Repository paragraph of this
class definition.
- Attribute-clause is defined in the topic on the
Attribute, Custom-Attribute Clause.
General Rules
- Class-name-1 names the class declared by this class definition. However, literal-1, if specified, is the name of the class
that is externalized to the operating environment.
- The INHERITS clause specifies the name of the class that is inherited by class-name-1 according to
Class inheritance.
- If the FINAL clause is specified, the class must not be the superclass for any other class.
- The PARTIAL phrase specifies that this is a partial class that may be combined with one or more other partial classes with
the same externalized name to form a single combined class. This may be combined using the ILSOURCE directive.
- The USING phrase specifies that this is a parameterized class. Parameter-name-1 is the name given to the formal parameter.
See the topic
Parameterized Classes in the chapter
Language Fundamentals for details of the behavior of a parameterized class.
When USING is specified for a class that is being compiled for .NET, the resulting class is known as a generic class. Constraints
for the parameters may be specified in the Constraints paragraph.
- Parameter-name-1 must be specified within this class definition only where a class-name or an interface-name is permitted.
- If the same class is inherited more than once, then only one copy of the data for that class is added to class-name-1.
Note: While the same class cannot be directly inherited more than once, a class may be indirectly inherited multiple times. For
example, suppose class D inherits from classes B and C, and classes B and C both inherit from class A. In this example, class
D indirectly inherits class A twice, once as a superclass of B, and once as a superclass of C.
- If STATIC is specified, all methods in a class are static.