2022-07-26:以下go语言代码输出什么?A:5;B:hello;C:编译错误;D:运行错误
2022-07-26:以下 go 语言代码输出什么?A:5;B:hello;C:编译错误;D:运行错误。
package main
import (
"fmt"
)
type integer int
func (i integer) String() string {
return "hello"
}
func main() {
fmt.Println(integer(5))
}
答案 2022-07-26:
答案选 B。调用的是 interger 的 String 方法,所以是 hello。不要被 integer 是整型所迷惑。
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: