package main
import (
"fmt"
)
//定义接口
type human interface {
//只有声明没有实现,也没有类型
eat()
}
type Student struct {
name string
}
//实现接口方法
func (s *Student) eat() {
fmt.Println(s.name + " eat")
}
func main() {
s := Student{"yy"}
(&s).eat()
}
Go语言 之接口的定义
原创
©著作权归作者所有:来自51CTO博客作者样子2018的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:PHP 之文件与目录
下一篇:Go语言 之延迟调用defer
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章