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 协议》,转载必须注明作者和本文链接
微信公众号:福大大架构师每日一题。最新面试题,涉及golang,rust,mysql,redis,云原生,算法,分布式,网络,操作系统。
讨论数量: 3

肯定是hello啊,不是直接写死hello了吗 allgoodsfree.com/category/programm...

1年前 评论

为什么呢

1年前 评论
moonfdd (楼主) 1年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
464
粉丝
21
喜欢
37
收藏
22
排名:461
访问:1.9 万
私信
所有博文
社区赞助商