




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、甲骨文程序設計大賽試題姓名: 專業班級: 一、單項選擇題:1. Map<String, ? extends Collection<Integer>>map;請問以下哪個賦值語句會出錯?(D)A、map=new HashMap<>( );JDK7支持B、map=new HashMap<String ,List<Integer>>( );C、map=new HashMap<String, LinkedList<Integer>>( );D、map=new LinkedHashMap<Object , List
2、 <Integer>>( );2.代碼片段:public class Certkiller3 implements Runnable public void run( ) System.out.print("running"); public static void main(String args) Thread t = new Thread(new Certkiller3( ); t.run( ); t.run( ); t.start( ); 運行結果是(E)。A、編譯出錯 B、運行時拋出異常 C、代碼正常執行并且輸出:runningD、代碼正常執行并
3、且輸出:runningrunning E、代碼正常執行并且輸出:runningrunningrunnng3. 代碼片段:public class Test private int a; public int b; protected int c; int d; public static void main(String args) Test test = new Test( ); int a = test.a+; int b = test.b-; int c = test.c+; int d = test.d-; System.out.println(a + " - "
4、+ b + " - " + c + " - " + d); 下列哪個說法是正確的?(C) A、編譯錯誤,因為變量a,b,c和d沒有被初始化 B、編譯錯誤,因為變量a無法被訪問C、編譯成功并輸出0000 D、編譯成功并輸出1 - - 1 1 - - 14. 代碼片段1:public class ComplexCalc public int value; public void calc( ) value += 5; 代碼片段2:public class MoreComplexCalc extends ComplexCalc public void calc
5、( ) value -= 2; public void calc(int multi) calc( ); super.calc( ); value *= multi; public static void main(String args) MoreComplexCalc calc = new MoreComplexCalc( ); calc.calc(3); System.out.println("Oh it is: " + calc.value); 請問編譯運行結果是 ?( A)A、Oh it is: 9 B、編譯出錯 C、Oh it is: 15 D、Oh it is
6、: -6 E、代碼正常執行但沒有輸出 F、運行時拋出異常 G.、Oh it is: 6 H、Oh it is: -155. 代碼片段:void waitForSignal( )Object obj=new Object( );synchronized(Thread.currentThread( )obj.wait( );obj.notify( );以下哪個描述是正確的?( A)A、需要處理InterruptedException B、代碼能編譯但可能運行時拋出IllegalStateException C、運行10分鐘后代碼拋出TimeOutException D、需要把obj.wait( )
7、替換為(Thread)obj).wait( )后代碼才能通過編譯。E、把obj.wait( )和obj.notify( )這兩句調換一下位置,能使代碼執行。6.代碼片段:contestKiller=new ReallyBigObject( );/這里省略部分代碼contestKiller=null;/*在這里補充代碼*/以下哪一項的代碼是告訴虛擬機盡最大的能力去回收contestKiller這個對象所占用的內存?( B )A、Runtime.getRuntime( ).freeMemory( ) B、Runtime.gc( )C、System.freeMemory( ) D、Runtime.g
8、etRuntime( ).growHeap( )7. 代碼片段:public void aSafeMethod(Object value)/在這里檢查方法的參數/這里省去其他的代碼Sytem.out.println(value.toString( );代碼中的方法要求傳入的參數是非空的,請問有什么比較好的方式去處理一個空值?(B)A、assert value=null;B、if(value=null)throw new IllegalArgumentException(“value can not be null”);C、if(value=null)throw new AssertionExc
9、eption(“value can not be null”);D、assert value !=null :”value can not be null”;8. 代碼片段:package certkiller;class Targetpublic String name=”hello”;哪些類能夠直接訪問并且改變name這個變量的值?( A )A、任意類 B、只有Target這個類 C、certkiller包下的類 D、Target的子類9. 代碼:String text="Welcome to Java contset"String words=text.split(&
10、quot;s");System.out.println(words.length);請問編譯運行的結果是什么?( D )A、0 B、1 C、4 D、編譯出錯 E、運行時拋出一個異常10. 代碼: String elements= "for","tea","too" ; String first=( elements.length > 0 ) ? elements0 : null ;以下哪個是正確的結果?(D)A、編譯失敗 B、運行時拋出異常 C、first的值被設為null D、first的值被設為“for”11. 代
11、碼片段: System.out.format("Pi is approximately %d.", Math.PI);請問執行的結果是什么?(D)A、編譯出錯 B、Pi is approximately 3. C、Pi is approximately 3.141593. D、運行時拋出異常12. 代碼:public class Test public Test( )System.out.print("test ");public Test(String val)this( );System.out.print("test with "
12、;+val);public static void main(String args)Test test=new Test("wow");請問編譯運行的結果是什么?( B )A、test B、test test with wow C、test with wow D、編譯失敗13. 代碼片段:public class JavaContest public static void fun(short n)System.out.print("short ");public static void fun(Short n)System.out.print(&qu
13、ot;SHORT "); public static void fun(Long n)System.out.print("LONG ");public static void main(String args)Short y=0;int z=y;fun(y);fun(z);請問編譯運行的結果是什么?( C )A、short Long B、SHORT LONG C、編譯出錯 D、運行時拋出異常14. 如下代碼:public static void main(String args)method1(1,2);System.out.print(" java&q
14、uot;); public static void method1(int x1,int x2)System.out.print("hello");public static void method1(int x1,int x2,int x3)System.out.print("hi");請問編譯運行的結果是什么?( A )A、hello java B、編譯失敗 C、hi java D、hellohi java E、hihello java15. 代碼:public class Person private String name; public Per
15、son(String name) =name; public boolean equals(Person p) return .equals(); 哪個選項的描述是正確的?( C )A、equals方法沒有正確覆蓋Object類中的equals方法B、編譯這段代碼會出錯,因為第五行的私有屬性訪問不到。C、如果要與基于哈希的數據結構一起正常地工作,只需要在這個類中再實現hashCode方法即可。D、當添加一組Person對象到類型為Java.util.Set的集合時,第四行中的equals方法能避免重復。二、多項選擇題:16. 給出一個
16、尚未使用泛型的方法:11. public static int getSum(List list)12. int sum=0;13.for(Iterator iter=list.iterator( ) ; iter.hasNext( ) ; ) 14.int i=(Integer)iter.next( ).intValue( );15.sum+=i;16.17.return sum;18.為了使用泛型,需要對代碼做一下那三項改動?( ACF )A、刪除第14行 B、第14行替換成int i=iter.next( );C、將第13行替換成for(int i:intList)D、將第13行替換成f
17、or(Iterator iter: intList)E、方法的參數聲明改為getSum(List<int> intList)F、方法的參數聲明改為getSum(List<Integer> intList)17. 代碼片段:public abstract interface Sudo public void crazy(String s); 請問以下哪些選項中的類定義是正確的?( BC )A、public abstract class MySudo implements Sudopublic abstract void crazy(String s) B、public a
18、bstract class YourSudo implements SudoC、public abstract class HerSudo implements Sudopublic void crazy(String i) public void crazy(Integer s) D、public class HisSudo implements Sudopublic void crazy(Integer i) E、 public class ItsSudo extends Sudopublic void crazy(Integer i) 18. public class Test publ
19、ic static void main(String args)int i=3,j;outer: while(i>0) j=3;inner: while (j>0)if(j<2) break outer;System.out.println(j+" and "+i);j-;i-;請問哪些選項的內容會出現在輸出中?(AE )A、3 and 3 B、3 and 2 C、3 and 1 D、3 and 0 E、 2 and 319.如下代碼: import java.io.*;class Directories static String films="
20、;sora","shu"public static void main(String args)for(String fp : films) /在這里插入第一句代碼File file=new File(path,args0);/在這里插入第二句代碼有一個文件夾,他有2個子文件夾,分別是“sora”和“shu”,“sora”里面有只名為“aoi.txt”的文件,“shu”里面只有名為“qi.txt”的文件。在此文件夾下以執行以下命令:java Directories qi.txt輸出結果是:“false true”.請問把以下哪些選項的代碼分別插入到上面代碼中能達到
21、此效果?( AC)A、/第一句代碼String path=fp;/第二句代碼 System.out.print(file.exists( )+”);B、/第一句代碼String path=fp;/第二句代碼 System.out.print(file.isFile( )+”);C、/第一句代碼String path=File.separator+fp;/第二句代碼System.out.print(file.exists( )+”);D、/第一句代碼 String path=File.separator+fp;/第二句代碼System.out.print(file.isFile( )+”);20
22、. 以下哪些選項的代碼存在錯誤JDK7支持在數字之間加空格?(ABCDEF)A、long n1=12_3_45_789; B、long n2=_123_45_678_9;C、int n3=0xFc_aB_C3_353; D、double n4=0b11001_001_0_0_11;E、float n5=1.4_142_13;F、float n6=0_1_2_3;三、編程題:21.考查知識點:1. 靜態方法關鍵字 static2. 方法重載,通過參數類型區分方法寫一個名叫Square的類用于求一個數的平方。類里面提供兩個靜態方法,名字叫square。其中一個方法的參數和返回值都是long類型,另
23、一個方法的參數和返回值是double型。public class Square public static long square(long l) return l;public static double square(double d) return d;22.考查知識點:1. 接口實現要重寫接口中的所有方法,且帶方法體;2. 重寫方法的訪問修飾符為public3. 重寫方法的要加上return ;給出以下接口HelloWorld,請編寫一個類MyHelloWorld實現該接口,并滿足接口中所要求的功能。給定如下的代碼:public interface HelloWorld /* * 返回
24、name+" say:hello world!". */String sayHelloWorld(String name);請您寫出一個類名為MyHelloWorld的類,要求滿足題意。public class MyHelloWorld implements HelloWorld public String sayHelloWorld(String name) return name+" say:hello world!" 23.給出如下shape類,請實現一個共有類Rectangle,滿足以下要求:1. 繼承于Shape,實現Shape所規定的功能2.
25、 有int類型的width和height屬性(寬和高)及相應的getter和setter3. 有一個帶兩個int參數的共有構造方法,第一個參數用于設置寬,第二個參數用于設置高給定如下代碼:public abstract class Shape /* * 計算形狀的面積 */abstract public int getArea( );請寫出一個類名為Rectangle的類,要求能滿足題意。public class Rectangle extends Shape private int width; private int height; public Rectangle(int width,i
26、nt height) this.width=width; this.height=height; public void setWidth(int width) this.width=width; public void setheight(int height) this.height=height; public int getWidth( ) return this.width; public int getHeight( ) return this.height; public int getArea( ) return getWidth( )*getHeight( ); 24. 在某軟件公司里,小蔡接到上頭的一個任務:某位離職的員工留下了一個接口IList,但是該接口的實現類的源碼卻已丟失,現在需要為該接口重新開發一個實現類MyList。下面提供了IList接口的代碼。要實現的MyList類是一個公有類,里面需要提供一個公有無參構造方法MyList( ),用于創建一個空的(不含任何元素的)IList。請你幫小蔡寫出這個實現類的
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年學校心理咨詢師專業職業資格考試試題及答案
- 2025年醫療器械工程師資格考試試卷及答案
- 2025年信息科學與數據政策考試試題及答案
- 2025年戲劇表演專業考前模擬題及答案
- 2025年文化產業發展考試試卷及答案研究
- Tyrosinase-IN-41-生命科學試劑-MCE
- 2025年流行病學與衛生統計考試試題及答案
- 2025年客戶關系管理相關考試試題及答案
- 2025年科學心理學綜合考試試題及答案
- 2025年電子信息工程師資格認證考試試題及答案
- 撤銷強制執行申請書
- 希臘文化介紹課件
- 2022-2023學年貴州省畢節市威寧縣小升初全真模擬數學檢測卷含答案
- BSCI驗廠全套程序文件
- 通用個人簡歷word模板
- 西屋破壁機料理機使用說明
- 2022-2023學年蘇教版高一數學新教材教學講義第4章 指數與對數 單元綜合測試卷
- 2023春國開個人與團隊管理模擬測試1試題及答案
- 蕪湖人教版七年級初一上冊地理期末測試題及答案
- 餐飲轉讓費協議書模板
- 中考說明文考點及答題技巧 【 知識精細梳理 】 中考語文提分必背
評論
0/150
提交評論