black

Java认证考试综合练习

登录

单项选择题

有下面代码importjava.util.*;classStudent{intage;Stringname;publicStudent(){}publicStudent(Stringname,intage){this.name=name;this.age=age;}publicinthashCode(){returnname.hashCode()+age;}publicbooleanequals(Objecto){if(o==null)returnfalse;if(o==this)returntrue;if(o.getClass()!=this.getClass())returnfalse;Studentstu=(Student)o;if(stu.name.equals(name)&&stu.age==age)returntrue;elsereturnfalse;}}publicclassTestHashSet{publicstaticvoidmain(Stringargs[]){Setset=newHashSet();Studentstu1=newStudent();Studentstu2=newStudent(“Tom”,18);Studentstu3=newStudent(“Tom”,18);set.add(stu1);set.add(stu2);set.add(stu3);System.out.println(set.size());}}下列说法正确的是()

A.编译错误
B.编译正确,运行时异常
C.编译运行都正确,输出结果为3
D.编译运行都正确,输出结果为2

相关考题

单项选择题 请甄别下列对二叉树的使用和理解正确的是()

单项选择题 java当中关于二叉树的理解错误的是()

单项选择题 关于hashcode()与equals()描述错误的是哪个()

All Rights Reserved 版权所有©求知题库网库(csqiuzhi.com)

备案号:湘ICP备14005140号-1

经营许可证号:湘B2-20140064