Declares the name of a class and defines its implementation.
[ modifier ] Class class_name [ < type_list > ] [ Is base_class ] [ Does trait_name ]... [ Where generic_constraints ] ... [ statements ] End [ Class ]
- Abstract – The class must be extended by a class that is not Abstract.
- Final – The class cannot be extended.
- Necessary identifier that names the class.
- Optional – One or more identifiers separated by commas and contained in angle brackets (< >).
- Optional name of another class from which this class inherits methods and properties.
- Optional, repeatable – Specifies which traits a class implements.
- The name of a trait, a way to define behavior. See Does Clause (Traits) for more information.
- Optional, repeatable – Specifies constraints to place on type arguments. Requires a type_list. You can place one at the end of the first line. Or you can place one or more on separate lines before any statements.
- One or more constraints on a generic parameter separated by commas. See Where Clause (Generics) for more information.
- Optional statements that define the members of the class.
- Completes the statement. You can also use End Class.
A Class statement defines a data type known as a class. Classes are fundamental building blocks in object-oriented programming (OOP). See Objects and Classes for more information.
You can place a Class only within certain contexts. These contexts include Program and Library modules, other classes, and Object and Trait declarations. You cannot place a class within a procedure. See Declaration Contexts and Default Access Levels for more information.
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 Begin Get Return my_name End Property Property Age As UInt16 Begin Get 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