Class Statement

Declares the name of a class and gives its implementation.


[ modifier ] Class class_name [ type_list ] [ Is base_class ] [ Does trait_name ]…
    [ Where generic_constraints ]…
    [ statements ]
End [ Class ]


Optional one of these:
  • @Abstract – The class must be extended by a class that is not abstract.
  • @Open – The class can be extended.
Mandatory name for the class.
Optional one or more names with commas between each, all between brackets ([ ]). See Type List for more information.
Optional name of a class from which this class inherits methods and properties.
Optional keyword that you can use again and again.
The name of a trait, a construct that specifies behavior. See Does Clause (Traits) for more information.
Optional, one or more times – Specifies constraints to put on type arguments from type_list. You can put one at the end of the first line, or you can have one or more, each on different lines, before statements.
One or more constraints on a generic parameter, with a comma between each. See Where Clause (Generics) for more information.
Optional statements that declare the members of the class.
Completes the statement. You can also use End Class.
You can change the syntax of this part. See @Option Directive for more information.


The statement Class makes a data type known as a class. Classes are important constructs in object-oriented programming (OOP). See Objects and Classes for more information.

You can put a class only in some contexts. These contexts include modules (Program and Library), other classes, and the constructs Object and Trait. You cannot put a class in a procedure. See Declaration Contexts and Default Access Levels for more information.

Permitted members


Example 1

Program ClassExample
Require IO

Class Person
    Var my_name As String, my_age As UInt16
    Constructor name As String, age As UInt16
        my_name = name
        my_age = age
    End Constructor
    Property Name As String
        Return my_name
    End Property
    Property Age As UInt16
        Return my_age
    End Property
End Class

Person #a, "Alice", 24
Person #b, "Bob", 42

PrintLine #a.Name & " is " & #a.Age
PrintLine #b.Name & " is " & #b.Age

' Output:
' Alice is 24
' Bob is 42

See also