# Constructors, methods, static methods, and this

A constructor is a same-name method inside a type. Instance methods can read this, while static methods belong to the type itself.

Last updated: 2026-09-09

Package: language | Status: stable

Tags: complete-program, cpu, data, language, static, this, yeho

Use a constructor to establish valid starting data, an instance method for behavior that belongs to one value, and static only when no instance state is needed.

```yh
Name(Type value) { this.field = value }
Method(...) -> Type { ... }
static Method(...) -> Type { ... }
```


## Self contained reference link

Use a constructor to establish valid starting data, an instance method for behavior that belongs to one value, and static only when no instance state is needed.

Verification: type checked

```yh
external class referenceCounter
{
    int value

    referenceCounter(int value)
    {
        this.value = value
    }

    Bump() returns int
    {
        this.value = this.value + 1
        return this.value
    }
}

referenceCounter counter = referenceCounter(41)
Console.Log(Text.Format("self-contained-reference={0}", counter.Bump()))

```

Save this beside start.yh as project.mech:

```toml
package = "tests.compiler.selfContainedReferenceLink"
version = "0.1.0"
selfContainedApp = true

```

Extract the example archive beside the yeho and dolphin checkouts. This example requires those source dependencies and a current developer compiler.

```sh
./yeho/build/dolphin-metal/yehoc ./api-examples/language--constructors-methods/complete --backend cpu-oracle -o /tmp/yeho-example
/tmp/yeho-example
```


Stored constructor values follow declaration order for the current value-data ABI.

Class dispatch remains a separate oracle-only boundary even though plain-data constructors and direct admitted calls run through Kyber.

Source: yeho/tests/compiler/kyber/plain-data-constructor/start.yh; tests/compiler/kyber/legalized-call-forms/start.yh

AI training permission: https://demonhunterlabs.com/ai-use
