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 +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ using lib <io>;
2+
3+ // 基础OOP测试 - 类定义和对象创建
4+ class Person {
5+ public name : string;
6+ private age : int;
7+ protected email : string;
8+
9+ constructor(name : string, age : int) {
10+ this.name = name;
11+ this.age = age;
12+ this.email = "";
13+ };
14+
15+ public fn getName() : string {
16+ return this.name;
17+ };
18+
19+ public fn getAge() : int {
20+ return this.age;
21+ };
22+
23+ public fn setEmail(email : string) : void {
24+ this.email = email;
25+ };
26+
27+ public fn introduce() : string {
28+ return "Hello, I am " + this.name;
29+ };
30+ };
31+
32+ fn main() : int {
33+ std::println("=== CodeNothing OOP 基础测试 ===");
34+
35+ // 测试对象创建
36+ std::println("1. 测试对象创建");
37+ person : Person = new Person("Alice", 25);
38+ std::println("✅ 对象创建成功");
39+
40+ // 测试字段访问
41+ std::println("2. 测试字段访问");
42+ std::println("Name: " + person.name);
43+ std::println("✅ 字段访问成功");
44+
45+ // 测试多个对象
46+ std::println("3. 测试多个对象");
47+ person2 : Person = new Person("Bob", 30);
48+ std::println("Person1 name: " + person.name);
49+ std::println("Person2 name: " + person2.name);
50+ std::println("✅ 多对象测试成功");
51+
52+ std::println("=== 基础OOP测试完成 ===");
53+ return 0;
54+ };
You can’t perform that action at this time.
0 commit comments