[GO]接口的嵌用继承

package main

import "fmt"

type Humaner interface {
    SayHi()
}

type Personer interface {
    Humaner
    Sing(lrc string)
}

type Student struct {
    name string
    id int
}

//实现接口的sayhi func (s
*Student)SayHi() { fmt.Printf("%s sayhi ", s.name) } func (p *Student)Sing(lrc string) { fmt.Printf("student %s sing %s ", p.name, lrc) } func main() {
  //定义一个接口的类型的变量
var i Personer s := &Student{"mike", 1} i = s i.SayHi() i.Sing("loving you ") }

执行结果为

mike sayhi
student mike sing loving you
原文地址:https://www.cnblogs.com/baylorqu/p/9642581.html