假如我有一个HUAWEI类,要实现Phone接口,能够这样做:
package main
import "fmt"
//定义一个接口
type Phone interface {
call()
}
//定义一个类
type HUAWEI struct {
name string
}
//用下面的HUAWEI类实现下面的Phone接口
func (myPhone HUAWEI) call() {
fmt.Println("this is the coolest phone all around the world")
}
func main() {
thisPhone := new(HUAWEI)
thisPhone.call()
}
发表回复