An example of using instance properties in the Haxe programming language.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A class; a template for creating objects with the properties listed in the class | |
class Duck { | |
public var age:Int; | |
public function new(age:Int) { | |
this.age = age; | |
} | |
} | |
class Test { | |
static function main() { | |
var ducky = new Duck(3); | |
trace(ducky.age); | |
// Using the instance variable to change the age | |
ducky.age = 4; | |
trace(ducky.age); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try it out here: https://try.haxe.org/#F52C8Aa3