Go 中文网、思否、博客园等平台,内容主要以问答形式记录。如果回答中有错误,欢迎大家指出,共同学习、共同进步。
Go每日一题_221
下面代码输出什么? type A interface { ShowA() int } type B interface { ShowB() int } type Work struct { i int } func (w Work) ShowA() int { return w.i + 10 } func (w Work) ShowB() int { return w.i + 20 } func main() { c := Work{3} var a A = c var b B = c fmt.Println(a.ShowB()) fmt.Println(b.ShowA()) } A. 23 13 B. compilation error 🔑 答案解析: 参考答案及解析:B。 a接口没有ShowB方法 b接口没有ShowA方法 因此编译不通过