Prev | Current Page 236 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

test(); // class name prefix is mandatory
}
}
class Sample {
public static function say() : String
{
return ???Hello!???;
}
public static function test() : Void
{
trace(say()); // same as trace(Sample.say());
}
}
Static Functions and Variables
The syntax for static functions is equal to the one of instance function with the insertion of the keyword
static between the access modifier and the function keyword.
The syntax to declare a static variable is the one depicted in Figure 5 - 5 .
private static var name : Type = assignament;
access
modifier
variable
name
optional value
assignament name
variable
type
Figure 5-5
115
Chapter 5: Delving Into Object-Oriented Programming
Values for static variables can be assigned in the variable declaration; when this is the case it is possible
to omit the variable type because the compiler is capable of inferring the correct type from the assigned
value. Contrary to many other languages, the values for static variables are computed during the
execution bootstrap and not when they are first invoked.


Pages:
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248