{"id":"language--constructors-methods","name":"Constructors, methods, static methods, and this","owner":"yeho","package":"language","kind":"language","signature":"Name(Type value) { this.field = value }\nMethod(...) -> Type { ... }\nstatic Method(...) -> Type { ... }","description":"A constructor is a same-name method inside a type. Instance methods can read this, while static methods belong to the type itself.","context":"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.","parameters":[],"returns":"","members":[],"tags":["complete-program","cpu","data","language","static","this","yeho"],"updated":"2026-09-09","source":{"repository":"yeho","path":"tests/compiler/kyber/plain-data-constructor/start.yh; tests/compiler/kyber/legalized-call-forms/start.yh"},"status":"stable","notes":["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."],"examples":[{"id":"complete","title":"Self contained reference link","description":"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.","code":"external class referenceCounter\n{\n    int value\n\n    referenceCounter(int value)\n    {\n        this.value = value\n    }\n\n    Bump() returns int\n    {\n        this.value = this.value + 1\n        return this.value\n    }\n}\n\nreferenceCounter counter = referenceCounter(41)\nConsole.Log(Text.Format(\"self-contained-reference={0}\", counter.Bump()))\n","manifest":"package = \"tests.compiler.selfContainedReferenceLink\"\nversion = \"0.1.0\"\nselfContainedApp = true\n","tags":["cpu","complete-program"],"verification":"type checked","run":"cpu-oracle","source":"tests/compiler/self-contained-reference-link/start.yh","sha256":"25ce6ec091d0c5994aca16dba5516b1d9c84d23231ed7e21ad8123badf29fa16","checked":"2026-09-09","diagnostic":"","observedOutput":null,"checkedBackend":null}],"searchTerms":[],"url":"https://demonhunterlabs.com/academy/api?item=language--constructors-methods","json":"https://demonhunterlabs.com/reference/items/language--constructors-methods.json","markdown":"https://demonhunterlabs.com/reference/text/language--constructors-methods.md"}
