itgle.com

importjava.util.*;classKeyMaster{publicinti;publicKeyMaster(inti){this.i=i;}publicbooleanequals(Objecto){returni==((KeyMaster)o).i;}publicinthashCode(){returni;}}publicclassMapIt{publicstaticvoidmain(String[]args){Setset=newHashSet();KeyMasterk1=newKeyMas

题目

importjava.util.*;

classKeyMaster{

publicinti;

publicKeyMaster(inti){this.i=i;}

publicbooleanequals(Objecto){returni==((KeyMaster)o).i;}

publicinthashCode(){returni;}

}

publicclassMapIt{

publicstaticvoidmain(String[]args){

Setset=newHashSet();

KeyMasterk1=newKeyMaster(1);

KeyMasterk2=newKeyMaster(2);

set.add(k1);set.add(k1);

set.add(k2);set.add(k2);

System.out.print(set.size()+:”);

k2.i=1;

System.out.print(set.size()+:”);

set.remove(k1);

System.out.print(set.size()+:”);

set.remove(k2);

System.out.print(set.size());

}

}

Whatistheresult?()


相似考题
更多“importjava.util.*;classKeyMaster{publicint ”相关问题
  • 第1题:

    importjava.util.*;publicclassLetterASort{publicstaticvoidmain(String[]args){ArrayListstrings=newArrayList();strings.add(?aAaA”);strings.add(”AaA”);strings.add(?aAa”);strings.add(”AAaa”);Collections.sort(strings);for(Strings:strings){System.out.print(s+);}}}Whatistheresult?()

    A.Compilationfails.

    B.aAaAaAaAAaaAaA

    C.AAaaAaAaAaaAaA

    D.AaAAAaaaAaAaAa

    E.aAaAaAaAaAAAaa

    F.Anexceptionisthrownatruntime.


    参考答案:C

  • 第2题:

    在下列源代码文件Test.java中, ( )是正确的类定义。

    A.public class test{

    B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }

    C.public class Test extends T1,T2{

    D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}


    正确答案:B

  • 第3题:

    7、以下程序的运行结果是()。 import java.util.*; public class Test{ public static void main(String[] args){ List<Integer> list= Arrays.asList(1,2,3,4); int sum=0; for(int s:list) sum+=s; System.out.println(sum); } }

    A.1234

    B.10

    C.1,2,3,4

    D.0


    HELLO! HELLO!

  • 第4题:

    importjava.util.*;publicclassPQ{publicstaticvoidmain(String[]args){PriorityQueuepq=newPriorityQueue();pq.add(”carrot”);pq.add(”apple”);pq.add(”banana”);System.out.println(pq.poll()+”:”+pq.peek());}}Whatistheresult?()

    A.apple:apple

    B.carrot:apple

    C.apple:banana

    D.banana:apple

    E.carrot:carrot

    F.carrot:banana


    参考答案:C

  • 第5题:

    8、下列程序执行的结果是___________。 import java.util.*; public class Example{ public static void main(String[] args){ String s="x,yy,123"; Scanner sc=new Scanner(s); while(sc.hasNext()){ System.out.print(sc.next()+" "); } } }

    A.x yy

    B.x,yy,123

    C.x yy 123

    D.x,yy


    B