Golang笔记-接口的实现

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)
}

猜你喜欢

转载自blog.csdn.net/u010931295/article/details/83182428