Class is a data structure that may contain data description (fields, constants, events), function members implementation (procedures/functions, properties, constructors), and nested types. Classes support inheritance, based on which a derived class can extend and specialize a basic class.
A class declaration consists of an optional set of class attributes, followed by an optional set of class modifiers, followed by the Class keyword and a class name. Next, a parent class and a list of interfaces that must implement the current class can be optionally specified. Then follows a class body followed by a sequence of End Class keywords. The class body determines a set of this class members.
A class signature may contain the Public or Friend access modifiers, as well as the Abstract or Finalmodifiers that indicate class purpose.
Abstract. It indicates whether a class is not final (incomplete) and can be used only as a basic one for other classes. It is not possible to explicitly create an abstract class instance, and it is a compilation error to use the New statement on an abstract class. While it is possible to have variables and values, which compile-time types are abstract, such variables and values at the runtime will necessarily either be empty or contain references to instances of non-abstract classes derived from this abstract type.
Final. It indicates whether a class is final, that is, it cannot be used as a basic one for other classes. A compilation error occurs if a final class is specified as the basic class of another class. The Final modifier is usually used to prevent an unintended inheritance but it also enables certain runtime optimizations. For example, it is possible to transform all virtual method invocations into non-virtual invocations because this class cannot have inherited classes.
//Class, available in the entire assembly, as well as in assemblies
//where this assembly is referenced to
Public Class Class1
End Class;
//Class available in entire assembly
Friend Class Class2
End Class;
//Abstract class
Abstract Class Class3
End Class;
//Class inherited from abstract
Class Class4: Class3
End Class;
//Final class that cannot have inherited classes
Final Class Class5
End Class;
A class body contains proper class members, and it can also be used to override parent class members.
Class members of a class are divided into the following categories:
Constants that are constant values associated with a class.
Fields that are class variables.
Constructors that determine actions required for initialization of objects of this class or the class itself.
Properties that determine named class characteristics and actions associated with getting and setting these characteristics.
Methods that implement the calculations and actions associated with a class.
Events that determine notifications that can be generated by a class.
Class members can be either instance or static members. Instance class members can be invoked from the class instance, static class members can be invoked directly from the class itself. Constants are implicitly static. To declare a static class member, the Shared modifier is specified in its signature.
If a class has a member, which name and signature fully match with a parent class member, the parent class member is hidden. In this case a compiler displays a warning. This is not an error; to hide a compiler warning, add the New modifier to the member signature.
When declaring properties or events the system reserves methods with a certain signature. Note this when declaring proper class members.
Class A
Public Shared Sub Test();
Begin
End Sub;
Public Function Test1(): Integer;
Begin
Return 1
End Function;
End Class;
Class B: A
New Public Shared Sub Test();
Begin
End Sub;
New Public Function Test1(): Integer;
Begin
Return 1
End Function;
End Class;
See also: