Whichfragmentisanexampleofinappropriateuseofassertions?()
A. assert(!(map.contains(x)));map.add(x);
B. if(x>0){}else{assert(x==0);}
C. publicvoidaMethod(intx){assert(x>0);}
D. assert(invariantCondition());returnretval;
E. switch(x){case1:break;case2:creak;default:assert(x==0);
查看答案
20.publicfloatgetSalary(Employeee){21.assertvalidEmployee(e);22.floatsal=lookupSalary(e);23.assert(sal>0);24.returnsal;25.}26.privateintgetAge(Employeee){27.assertvalidEmployee(e);28.intage=lookupAge(e);29.assert(age>0);30.returnage;31.}Whichlineisaviolationofappropriateuseoftheassertionmechanism?()
A. line21
B. line23
C. line27
D. line29
classA{protectedintmethod1(inta,intb){return0;}}WhichtwoarevalidinaclassthatextendsclassA?()
A. publicintmethod1(inta,intb){return0;}
B. privateintmethod1(inta,intb){return0;}
C. privateintmethod1(inta,longb){return0;}
D. publicshortmethod1(inta,intb){return0:}
E. staticprotectedintmethod1(inta,intb){return0;}
硬币制作的“硬币戒指”是否允许出售?()
A.首饰都允许出售,不管是否为硬币材质的
B.允许出售
C.不允许出售
D.不确定
publicclassTest{publicstaticvoidmain(Stringargs[]){classFoo{publicinti=3;}Objecto=(Object)newFoo();Foofoo=(Foo)o;System.out.println(i=+foo.i);}}Whatistheresult?()
A. i=3
B. Compilationfails.
C. AClassCastExceptionisthrownatline6.
D. AClassCastExceptionisthrownatline7.