Static — RexDac Academy

RexDac AcademyTechnical notes · Some prior knowledge helps
0%Published notes read · this device

Level 4 — Classes

Static

Original notes by SunDiaL · View English source

The static keyword is used to denote the absence of an instance. Something still exists though, so it's better to think of it like a "single, universal instance". The members belong to the type itself.

Static members

A static member does not need an instance to be accessed, it can be accessed directly through the class name.

Static classes

A static class cannot be instantiated -> can have only static members.

Example

public static class ExampleStaticClass
{
	public static int x;
}

public void main()
{
	ExampleStaticClass.x = 5;
	//notice how there is no instance created first.
}