• 2022-05-31
    给定如下Java代码,编译运行的结果是( )。public class Test {public static void main(String[] args) {Map<String, String> map = new HashMap<String, String>();String s = "code";map.put(s, "1");map.put(s, "2");System.out.println(map.size());}}
    A: 正确运行,输出:1
    B: 编译时发生错误
    C: 运行时引发异常
    D: 正确运行,输出:2
  • A

    举一反三

    内容

    • 0

      public static void main(String&#91;&#93; args) { LinkedList list=new LinkedList(); list.add("A"); list.add("B"); String s=(String)list.get(2); System.out.println(s); }编译运行的结果是 A: 运行时引发异常 B: 输出:B C: 编译时发生错误 D: 输出:A

    • 1

      阅读以下代码:import java.io.*; import java.util.*; public class foo{ public static void main (String&#91;&#93; args){ String s; System.out.println(&quot;s=&quot; + s); } }输出结果应该是:( ) A: 代码得到编译,并输出“s=” B: 代码得到编译,并输出“s=null” C: 由于String s没有初始化,代码不能编译通过 D: 代码得到编译,但捕获到 NullPointException异常

    • 2

      下列【1】【2】【3】【4】注释标注的哪行代码有错误?import java.util.*;public class E {public static void main(String args&#91;&#93;) {Map<;String,String>; map = new HashMap<;String,String>;(); //【1】Set<;Integer>; treeSet = new TreeSet<;Integer>;();//【2】Map<;String,String>; treeMap= new TreeMap<;String,String>;(); //【3】List<;char>; list = new LinkedList<;char>;(); //【4】 A: 【1】 B: 【2】 C: 【3】 D: 【4】

    • 3

      public static void main(String[] args) { LinkedList list=new LinkedList(); list.add("A"); list.add("B"); String s=(String)list.get(2); System.out.println(s); } 编译运行的结果是

    • 4

      有如下代码:public class Test{ public static void main(String args&#91;&#93;) { String str = new String(&quot;World&quot;); char ch&#91;&#93; = {'H','e','l','l','o'}; change(str,ch); System.out.println(str + &quot;and&quot; + ch); } public static void change(String str, char ch&#91;&#93;) { str = &quot;Changed&quot;; ch&#91;0&#93; = ' C'; }}运行后输出的结果是: A: Changed and Cello B: World and Cello C: World and CelloChanged and Hello D: World and Hello