本文共 507 字,大约阅读时间需要 1 分钟。
package mainimport "fmt"// 定义Persontype Person struct { name string}// 定义方法func (p *Person) show() { fmt.Println("name=" + p.name) p.print()}func (p *Person) print() { fmt.Println("Person print()")}// 定义Studenttype Student struct { Person stuNo string}/*//定义方法func (s * Student) show() { fmt.Println("name = " + s.name + ", stuNo=" + s.stuNo) s.print()}*///定义方法func (s * Student) print() { fmt.Println("Student print()")}func main() { p := Person{"chf"} p.show() s := Student{Person{"chf"}, "001"} s.show()}