Declares the beginning of an object class.
Class Identifier [ < Parameters > ] [ Extends Class ] [ Implements Interfaces ] [ Final ] ' Declarations... End [ Class ]
The Class keyword begins the declaration of a custom class. Classes can contain fields, methods, constants, globals and functions.
To access an object's fields, methods, constants, globals and functions, use the syntax object.identifier. (See example.)
Please see the Classes section of the monkey language reference for more information on classes.
End | Extends | Final | Method | Field | Function | Interface
Language reference
' Declaring class and fields...Class GameObject Field x:Float Field y:FloatEnd' Creating object "g" of type "GameObject"...Local g:GameObject = New GameObject' Accessing fields...g.x = 100g.y = 200Print g.xPrint g.y
Simple Extends example.
Class GameObject Field x:Float Field y:FloatEndClass Player Extends GameObject Field name:String Field points:Int = 0 Method PrintName () Print name EndEndLocal p:Player = New Player' Accessing fields, including those defined by' the class being extended...p.x = 100p.y = 200p.name = "Mary"p.points = 100Print p.xPrint p.yPrint p.points' Accessing method...p.PrintName