Classes

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.

Class Modifiers

A class signature may contain the Public or Friend access modifiers, as well as the Abstract or Finalmodifiers that indicate class purpose.

//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;

Class Body

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:

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:

Fore.NET Language Guide