package main

import "fmt"

type Human struct {
	name   string
	age    int
	weight int
}
type Student struct {
	Human
	speciality string
}

func main() {
	mark := Student{Human{"Mark", 25, 120}, "Computer Science"}
	fmt.Println("His  name is ", mark.name)
	fmt.Println("His age is", mark.age)
	fmt.Println("His weight is ", mark.weight)
	fmt.Println("His  speciality is ", mark.speciality)
	mark.speciality = "AI"
	fmt.Println("Mark changed his speciality")
	fmt.Println("His speciality is ", mark.speciality)
	fmt.Println("Mark become old")
	mark.age = 46
	fmt.Println("His age is ", mark.age)
	fmt.Println("Mark is not an athlet anymore")
	mark.weight += 60
	fmt.Println("His weight is", mark.weight)
}

 上面介绍了如何定义一个struct,定义的时候是字段名与其类型一一对应,实际上GO支持只提供执行,而不写字段名的方式,也就是匿名字段,也称为嵌入字段。当匿名字段是一个st