GOLANG的继承语法练习

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()
}

 最终结果:app

相关文章
相关标签/搜索