java基础问题疑惑

susuyjh susuyjh 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
12、分析下面的代码,其输出结果是( )。
  1. public class Test {
  2. public static void main (String [] args) {
  3. string foo = "blue";
  4. string bar = foo;
  5. foo = "green";
  6. System.out.printIn(bar);
  7. }
  8. }
  A. 一个异常抛出
  B. 代码无法编译
  C. null
  D. blue
  E. green
  知识点列表:4.1 系统定义的类(包)。
正确答案是选择D,我是选择E,我是认为在第四行,bar不是已经引用了foo的内存地址,然后又把”green“赋予给foo,不就相当与给foo里"blue"重新赋予green值吗,我搞混了,望高手请教下
...全文
评论 11
收藏 已收藏
分享
返回顶部
susuyjh
Java SE 62,620 成员 307,251 内容