diff --git a/playground/Demo/Demo31/Main.snow b/playground/Demo/Demo31/Main.snow new file mode 100644 index 0000000..0d31c7f --- /dev/null +++ b/playground/Demo/Demo31/Main.snow @@ -0,0 +1,56 @@ +module: Main + import: os + + // 父类 Person + struct: Person + fields: + declare name: int + init: + params: + name: int + body: + this.name = name + end body + end init + + function: getName + returns: int + body: + return this.name + end body + end function + end struct + + // 子类 Student 继承 Person + struct: Student extends Person + fields: + declare studentId: int + init: + params: + name: int + studentId: int + body: + super(name) // 调用父类构造函数 + this.studentId = studentId + end body + end init + + function: getStudentId + returns: int + body: + return this.studentId + end body + end function + end struct + + function: main + returns: void + body: + declare s: Student = new Student(123, 1001) + + // Student 拥有父类方法 + os.println(s.getName()) // 来自 Person → 123 + os.println(s.getStudentId()) // 来自 Student → 1001 + end body + end function +end module diff --git a/playground/Demo/Demo31/OS.snow b/playground/Demo/Demo31/OS.snow new file mode 100644 index 0000000..7c6de6f --- /dev/null +++ b/playground/Demo/Demo31/OS.snow @@ -0,0 +1,18 @@ +module: os + function: print + params: + declare i1: int + returns: void + body: + syscall("PRINT", i1) + end body + end function + function: println + params: + declare i1: int + returns: void + body: + syscall("PRINTLN", i1) + end body + end function +end module