Debian Codegraph @

src/test/05-Global/98.ck

raw
1 // global variable used from within a public class
2 //
3 // NOTE this would not work if NOT explicitly global, and would
4 // results in an error, since public class X uses 'foo', but a
5 // non-global int would only be file-scope whereas a public class
6 // can be instantiated from any file
7 //
8 // SEE ALSO:
9 // 06-Errors/error-public-class-ext-var1.ck
10 // 06-Errors/error-public-class-ext-var2.ck
11
12 // global int
13 7 => global int foo;
14
15 // public classes can be instantiated from any file
16 public class X
17 {
18 fun void go()
19 {
20 // this is OK since foo is declared as "global"
21 if( (foo + 5) == 12 ) <<< "success" >>>;
22 }
23 }
24
25 // evaluate, this will be on a different file context
26 Machine.eval( "X x; x.go();" );