Go的组合继承

来源:互联网 发布:淘宝卖家中心登录网 编辑:程序博客网 时间:2024/06/06 14:14
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 {PersonstuNo 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()}

原创粉丝点击