This repository was archived by the owner on Aug 18, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ using lib <io>;
2+
3+ // 静态成员测试类
4+ class MathUtils {
5+ static PI : float = 3.14159;
6+ static counter : int = 0;
7+
8+ static fn add(a : int, b : int) : int {
9+ return a + b;
10+ };
11+
12+ static fn getPI() : float {
13+ return MathUtils::PI;
14+ };
15+ };
16+
17+ class Person {
18+ public name : string;
19+ static totalCount : int = 0;
20+
21+ constructor(name : string) {
22+ this.name = name;
23+ };
24+
25+ public fn getName() : string {
26+ return this.name;
27+ };
28+ };
29+
30+ fn main() : int {
31+ std::println("=== CodeNothing 静态成员测试 ===");
32+
33+ // 测试静态字段访问
34+ std::println("1. 测试静态字段访问");
35+ pi : float = MathUtils::PI;
36+ std::println("PI = " + pi);
37+ std::println("✅ 静态字段访问成功");
38+
39+ // 测试对象创建
40+ std::println("2. 测试对象创建");
41+ person : Person = new Person("Alice");
42+ std::println("Person name: " + person.getName());
43+ std::println("✅ 对象创建成功");
44+
45+ // 测试静态字段访问
46+ std::println("3. 测试多个静态字段");
47+ count : int = Person::totalCount;
48+ std::println("Total count: " + count);
49+ std::println("✅ 静态成员测试成功");
50+
51+ std::println("=== 静态成员测试完成 ===");
52+ return 0;
53+ };
You can’t perform that action at this time.
0 commit comments