Declares the name of a class and defines its implementation.
[ Abstract ] Class name [ < typeList > ] [ Is superclass ] [ Does trait ]... [ Where genericConstraints ] ... [ statements ] End [ Class ]
- Optional — Specifies that this is an abstract class, and is ordinarily used as the parent of a concrete class.
- Required — An identifier that names the class.
- Optional — One or more identifiers separated by commas and surrounded by angle brackets (< >).
- Optional — The 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 typeList. 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 details.
- Optional — The statements that define the members of the class.
- Completes the Class statement. Alternatively, you can 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 #io Class Person Dim myName As String, myAge As UShort Constructor name As String, age As UShort myName = name myAge = age End Constructor Method GetName As String Return myName End Method Method GetAge As UShort Return myAge End Method End Class Person #a, "Alice", 24 Person #b, "Bob", 42 #io.WriteLine #a.GetName & " is " & #a.GetAge #io.WriteLine #b.GetName & " is " & #b.GetAge End ' Output: ' Alice is 24 ' Bob is 42