




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 投標文件密封檢查表
- Brand KPIs for health insurance:Plan Seguro in Mexico-英文培訓課件2025.4
- 物理中考二輪復習教案 8實驗專題2(力學)
- 仔細研讀活動方案
- 仙林品牌活動策劃方案
- 代理進貨活動方案
- 以廠為家活動方案
- 以茶會友戶外活動方案
- 仰韶酒廠活動方案
- TJSQA-溫室氣體?產品碳足跡量化方法與要求?鋁合金型材產品
- 農村網格化管理制度
- 公交站牌制作合同協議書
- 旅行社之間旅游合作合同范本
- 湖南省岳陽市湘陰縣長侖四校2024-2025學年下學期 5月聯考八年級數學試題
- 2025年中考語文7-9年級上冊必背課文【現代文+古詩文】66篇(打印版)
- 鄉鎮養老院建設年度工作規劃
- 2025年中國煤炭裝備制造行業分析與發展策略咨詢報告(定制版)
- 2025-2030年中國微電網行業市場深度調研及發展前景與投資研究報告
- 2025山東濟南先行投資集團有限責任公司及權屬公司社會招聘169人筆試參考題庫附帶答案詳解
- 項目總工面試試題及答案
- 聯創合伙人協議合同協議
評論
0/150
提交評論