Created
September 4, 2021 16:45
-
-
Save KinoAR/a247e603dec17a1046a7918a9f241713 to your computer and use it in GitHub Desktop.
A gist displaying how to use the static vs instance properties.
This file contains hidden or 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 { | |
static public var CAN_FLY:Bool = true; | |
public var age:Int; | |
public function new(age:Int) { | |
this.age = age; | |
} | |
} | |
class Test { | |
static function main() { | |
var ducky = new Duck(3); | |
// A static property uses the class name in order to access the element | |
trace(Duck.CAN_FLY); | |
// ducky.CAN_FLY = false; //Try uncommenting this line and see what happens | |
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
https://try.haxe.org/#51b3Db97 You can try the example here.