答案:和java一样,需要全部实现所有接口方法,如果不实现所有接口方法,意味着没有继承这个接口。
代码链接:接口代码实现---链接
package main
import (
"fmt"
)
type Phone interface {
call()
start()
}
type NokiaPhone struct {
}
func (nokiaPhone NokiaPhone) call() {
fmt.Println("I am Nokia, I can call you!")
}
func (nokiaPhone NokiaPhone) start() {
fmt.Println("I am Nokia, I can call you!")
}
type IPhone struct {
}
func (iPhone IPhone) call() {
fmt.Println("I am iPhone, I can call you!")
}
func (iPhone IPhone) start() {
fmt.Println("I am iPhone, I can start you!")
}
func main() {
var phone Phone
phone = new(NokiaPhone)
phone.call()
phone = new(IPhone)
phone.call()
}