




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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”,“l(fā)ogmessage5”,“l(fā)ogmessage6);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”.
編程題:
請(qǐng)完成下列程序中的insert()函數(shù),完成雙向鏈表的建立,并使得鏈表中的元素從小到大有序排列。
publicclassTestDuLink{
publicstaticvoidmain(Stringargs[]){
DuLinkl=newDuLink();l.insert("4");
l.insert("6");
l.insert("5");
l.insert("1");
l.insert("2");
l.insert
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025福建福州市城鄉(xiāng)建總集團(tuán)有限公司權(quán)屬企業(yè)社會(huì)招聘12人筆試參考題庫(kù)附帶答案詳解
- 2025年罕見病藥物研發(fā)激勵(lì)政策與產(chǎn)業(yè)政策創(chuàng)新趨勢(shì)分析報(bào)告
- 創(chuàng)新型農(nóng)林經(jīng)管人才培養(yǎng)的關(guān)鍵舉措
- 行政監(jiān)督機(jī)制解析與試題及答案
- TFT光掩膜基板項(xiàng)目規(guī)劃設(shè)計(jì)方案(模板范文)
- 2024水電工程大數(shù)據(jù)應(yīng)用前景試題及答案
- 中級(jí)經(jīng)濟(jì)師對(duì)外經(jīng)濟(jì)關(guān)系試題及答案解析
- 工程經(jīng)濟(jì)實(shí)務(wù)操作試題及答案
- 地下空間利用的安全性試題及答案
- 2025年經(jīng)濟(jì)師試題練習(xí)冊(cè)試題及答案
- 第三屆南華大學(xué)醫(yī)學(xué)生臨床技能競(jìng)賽評(píng)分標(biāo)準(zhǔn)高處
- 民用航空器駕駛員學(xué)校合格審定規(guī)則(完整版)
- 2025超市承包經(jīng)營(yíng)合同
- 安全紀(jì)律教育主題班會(huì)
- 2025-2030中國(guó)橋梁檢查與維護(hù)行業(yè)市場(chǎng)發(fā)展趨勢(shì)與前景展望戰(zhàn)略研究報(bào)告
- 泡沫混凝土施工方案
- 麻家梁煤礦8.0Mt-a新井設(shè)計(jì)- 厚煤層富水頂板控水開采技術(shù)
- 2025年高空車作業(yè)考試題及答案
- 蜱蟲預(yù)防卡通
- 股骨干骨折知識(shí)
- 非遺文化產(chǎn)業(yè)發(fā)展-深度研究
評(píng)論
0/150
提交評(píng)論