package main import( "fmt" _"sort" _"math/rand" ) // type WuDangMaster struct { Name string Age int } func (master *WuDangMaster) kongfu() { fmt.Println(master.Name,"秘籍:武当太极十三式") } //apprentice 美 /?‘pr?nt?s/ n. 学徒;生手 type apprentice struct{ WuDangMaster //匿名结构体,继承WuDangMaster结构体内的字段(属性)及方法 } func main(){ var appr apprentice = apprentice{ WuDangMaster{ Name:"张翠山", Age:30, }, } appr.kongfu() }
最终结果:
原文:https://www.cnblogs.com/swei/p/10832444.html