test: 重构 Student 类并简化 Main 函数

This commit is contained in:
Luke 2025-09-01 15:33:33 +08:00
parent fefb44cda7
commit 5c48f4038b

View File

@ -1,32 +1,34 @@
module: main module: main
struct: Student extends Person import: os
struct: Student
fields: fields:
declare name: int
declare studentId: int declare studentId: int
init: init:
params: params:
name: int name: int
studentId: int studentId: int
body: body:
super(name) this.name = name
this.studentId = studentId this.studentId = studentId
end body end body
end init end init
// 新增:无参数构造
init: init:
params: params:
body: body:
super(0) this.name = 0
this.studentId = 0 this.studentId = 0
end body end body
end init end init
// 新增:只带 name
init: init:
params: params:
name: int name: int
body: body:
super(name) this.name = name
this.studentId = -1 this.studentId = -1
end body end body
end init end init
@ -45,12 +47,9 @@ module: main
declare a: Student = new Student(123, 1001) declare a: Student = new Student(123, 1001)
declare b: Student = new Student() declare b: Student = new Student()
declare c: Student = new Student(88) declare c: Student = new Student(88)
os.println(a.getName()) // 123 println(a.getStudentId())
os.println(a.getStudentId()) // 1001 println(b.getStudentId())
os.println(b.getName()) // 0 println(b.getStudentId())
os.println(b.getStudentId()) // 0
os.println(c.getName()) // 88
os.println(c.getStudentId()) // -1
end body end body
end function end function
end module end module