- 重写
package main
import "fmt"
type person struct {
id int
name string
}
type student struct {
person
class int
}
func (p *person8) Say() {
fmt.Printf(p.name)
}
//子类对象和父类对象的方法名重名
func (s *student8) Say() {
fmt.Printf(s.class)
}
func main() {
stu := student8{person8{1001, "wang"}, 112,}
//子类对象方法 采用就进原则 使用子类对象方法
stu.Say()
//父类对象方法
stu.person.Say()
fmt.Println(stu.SayHello)
fmt.Println(stu.person8.SayHello)
}