package main
import "fmt"
type run interface {
jump()
}
type Bird struct {
}
func (b Bird) jump() {
fmt.Println("bird jump")
}
type Dog interface {
eat()
sleep()
run
}
type xh struct {
run
}
func (x xh) eat() {
fmt.Println("eat")
}
func (x xh) sleep() {
fmt.Println("sleep")
}
func fly(dog Dog) {
fmt.Println("fly")
}
func newXh() xh {
xh1 := xh{new(Bird)}
return xh1
}
func main() {
xh := newXh()
xh.eat()
xh.jump()
xh.sleep()
fly(xh)
}
Golang笔记-接口的实现
最新推荐文章于 2023-12-08 19:00:00 发布