41_接口的嵌入

package main

import "fmt"

type Hummaner interface {
	sing() //声明一个方法,并没有实现
}
type Studenter interface {
	Hummaner //匿名字段,嵌入字段
	play()   //声明一个方法,并没有实现
}
type Student struct {
	id   int
	name string
}

//type Techer struct {
//	id   int
//	name string
//}

func (s *Student) sing() {
	fmt.Println("学生在唱歌!!!")
}
func (t *Student) play() {
	fmt.Println("老师在玩耍!!!")
}
func main() {
     var s Studenter//接口类型变量
	var s1 *Student = &Student{1, "赵"}
	s = s1
	//可以调用继承来的接口方法
	s.sing()
	s.play()
}
每天的价值就是不停息的前进!!!
原文地址:https://www.cnblogs.com/zhaopp/p/11565507.html