static
- Last UpdatedNov 06, 2025
- 1 minute read
The static keyword is only allowed on class variables and methods.
Static variables are accessible directly by any object accessing the class.
Static methods can be directly accessed using the scope resolution operator (::) and the fully qualified name; for example, Test::TestClass.testInstance()
Non-static class variables or methods are available only when the associated class is instanced, by using ScriptObject.
Code example
The following example shows how to use static keyword.
namespace Test
{
class TestClass
{
public int val_1; //an int instance variable
public static string val_2; //a string class variable
public static void testInstance()
{
// can be accessed with Test::TestClass.testInstance()
}
void testInstance2()
{
// can be accessed only after creating an instance of the class
// <ScriptObject name="testObject2" class="XR::Test::TestClass2"/>
//…
// <route from="Z.keyDown" to="testObject2.test"/>
}
}
}