




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Betax=newBeta();
//insertcodehere
}
}
Whichcode,insertedatline16,willcauseajava.lang.ClassCastException?
Alphaa=x;
Foof=(Delta)x;
Foof=(Alpha)x;
Betab=(Beta)(Alpha)x;
Question4
WhichManclassproperlyrepresentstherelationship“ManhasabestfriendwhoisaDog”?
classManextendsDog{}
classManimplementsDog{}
classMan{privateBestFrienddog;}
classMan{privateDogbestFriend;}
classMan{privateDog<bestFriend>}
classMan{privateBestFriend<dog>}
Question5Given:
Object[]myObjects={
newinteger(12),
newString(”foo”),
newinteger(5),
newBoolean(true)
};
Arrays.sort(myObjects);
for(inti=0;i<myObjects.length;i++){
System.out.print(myObjects[i].toString());
System.out.print(”“);
}
Whatistheresult?
Compilationfailsduetoanerrorinline23.
Compilationfailsduetoanerrorinline29.
AClassCastExceptionoccursinline29.
AClassCastExceptionoccursinline31.
Thevalueofallfourobjectsprintsinnaturalorder.
Question6
Given:
publicclassPass{
publicstaticvoidmain(String[]args){
intx=5;
Passp=newPass();
p.doStuff(x);
System.out.print(”mainx=“+x);
}
voiddoStuff(intx){
System.out.print(”doStuffx=“+x++);
}
}
Whatistheresult?
Compilationfails.
Anexceptionisthrownatruntime.
doStuffx=6mainx=6
doStuffx=5mainx=5
doStuffx=5mainx=6
doStuffx=6mainx=5
Question7Given:
classNav{
publicenumDirection{NORTH,SOUTH,EAST,WEST}
}
publicclassSprite{
//insertcodehere
}
Whichcode,insertedatline14,allowstheSpriteclasstocompile?
Directiond=NORTH;
Nav.Directiond=NORTH;
Directiond=Direction.NORTH;
Nav.Directiond=Nav.Direction.NORTH;
Question8Given:
publicstaticvoidparse(Stringstr){
try{
floatf=Float.parseFloat(str);
}catch(NumberFormatExceptionnfe){
f=0;
}finally{
System.out.println(f);
}
}
publicstaticvoidmain(String[]args){
parse(”invalid”);
}
Whatistheresult?
0.0
Compilationfails.
AParseExceptionisthrownbytheparsemethodatruntime.
ANumberFormatExceptionisthrownbytheparsemethodatruntime.
Question9
Aprogrammerneedstocreatealoggingmethodthatcanacceptanarbitrarynumberofarguments.Forexample,itmaybecalledinthese
ways:
logIt(”logmessage1“);
logIt(”logmessage2”,”logmessage3”);
logIt(”logmessage4”,“logmessage5”,“logmessage6);Whichdeclarationsatisfiesthisrequirement?
publicvoidlogIt(String*msgs)
publicvoidlogIt(String[]msgs)
publicvoidlogIt(String...msgs)
publicvoidlogIt(Stringmsg1,Stringmsg2,Stringmsg3)
Question10
ClicktheExhibitbutton.
1.publicclassA{2.
3.privateintcounter=0;
4.
publicstaticintgetInstanceCount(){
returncounter;
}
publicA(){
counter++;
}
}
GiventhiscodefromClassB:
Aa1=newA();
Aa2=newA();
Aa3=newA();
System.out.printIn(A.getInstanceCount());Whatistheresult?
CompilationofclassAfails.
Line28printsthevalue3toSystem.out.
Line28printsthevalue1toSystem.out.
Aruntimeerroroccurswhenline25executes.
Compilationfailsbecauseofanerroronline28.
Question11Given:
publicstaticvoidmain(String[]args){
for(inti=0;i<=10;i++){
if(i>6)break;
}
System.out.println(i);
}
Whatistheresult?
6
7
10
11
Compilationfails.
Anexceptionisthrownatruntime.
Question12
Given:
publicstaticvoidsearch(List<String>list){
list.clear();
list.add(”b”);
list.add(”a”);
list.add(”c”);
System.out.println(Collections.binarySearch(list,“a”));
}
WhatistheresultofcallingsearchwithavalidListimplementation?
0
1
2
a
b
c
Theresultisundefined.
Question13
ClicktheExhibitbutton.
classFoo{
privateintx;
publicFoo(intx){this.x=x;}
publicvoidsetX(intx){this.x=x;}
publicintgetX(){returnx;}
}
publicclassG{18.
staticFoofooBar(Foofoo){
foo=newFoo(100);
returnfoo;
}
publicstaticvoidmain(String[]args){
Foofoo=newFoo(300);
System.out.print(foo.getX()+“-“);27.
FoofooFoo=fooBar(foo);
System.out.print(foo.getX()+“-“);
System.out.print(fooFoo.getX()+“-“);31.
foo=fooBar(fooFoo);
System.out.print(foo.getX()+“-“);
System.out.prmt(fooFoo.getX());
}
}
Whatistheoutputofthisprogram?
300-100-100-100-100
300-300-100-100-100
300-300-300-100-100
300-300-300-300-100
Question14
Given:
publicvoidgenNumbers(){
ArrayListnumbers=newArrayList();
for(inti=0;i<10;i++){
intvalue=i*((int)Math.random());
IntegerintObj=newInteger(value);
numbers.add(intObj);
}
System.out.println(numbers);
}
WhichlineofcodemarkstheearliestpointthatanobjectreferencedbyintObj esacandidateforgarbagecollection?
Line16
Line17
Line18
Line19
TheobjectisNOTacandidateforgarbagecollection.
Question15Given:
publicclassThreads3implementsRunnable{
publicvoidrun(){
System.out.print(”running”);
}
publicstaticvoidmain(String[]args){
Threadt=newThread(newThreads3());
t.run();
t.run();
t.start();
10.}
11.}
Whatistheresult?
Compilationfails.
Anexceptionisthrownatruntime.
Thecodeexecutesandprints“running”.
Thecodeexecutesandprints“runningrunning”.
Thecodeexecutesandprints“runningrunningrunning”.
编程题:
请完成下列程序中的insert()函数,完成双向链表的建立,并使得链表中的元素从小到大有序排列。
publicclassTestDuLink{
publicstaticvoidmain(Stringargs[]){
DuLinkl=newDuLink();l.insert("4");
l.insert("6");
l.insert("5");
l.insert("1");
l.insert("2");
l.insert
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 展台搭建合同范本
- 税务系统纳税信用管理政策解读
- 三农村创业投资手册
- 企业供应链管理的数字化转型及优化策略研究
- 三农产品质量安全追溯系统建设手册
- 新零售技术应用与发展趋势分析报告
- 停车场车辆出入智能管理系统
- 做可行性研究情况报告
- 生态农业观光园区采购
- 生物质颗粒燃料大锅灶
- 湖北省武汉市2024-2025学年高三2月调研考试英语试题
- 教科版三年级下册科学全册同步练习(一课一练)
- 内蒙古机电职业技术学院单独招生(机电类)考试题(附答案)
- 城市公园景观设计教学课件
- 2025年阜阳职业技术学院单招职业适应性测试题库及参考答案
- 人教版(2024)七下 第二单元第1课《精彩瞬间》课件-七年级美术下册(人教版)
- 六分钟步行试验记录表
- 1聚焦义务教育语文第三学段课标、教材与教学
- 《创新创业教育基础》课程教学大纲3篇
- 紫微斗数笔记Word版
- 输液泵、微量泵的使用PPT参考幻灯片
评论
0/150
提交评论