




已閱讀5頁,還剩13頁未讀, 繼續免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
班 級 學 號 姓 名 密封裝訂線 密封裝訂線 密封裝訂線A卷注意事項:請將各題答案按編號順序填寫到答題卷上,答在試卷上無效。一、單項選擇題(120每小題1分,2130每小題2分,共40分)1. Which are keywords in Java?A. NullB. TRUEC. sizeofD. implements2. Consider the following code:Integer s = new Integer(9);Integer t = new Integer(9);Long u = new Long(9);Which test would return true?A. (s.equals(new Integer(9)B. (s.equals(9)C. (s=u)D. (s=t)3. Which statement of assigning a long type variable to a hexadecimal value is correct? A. long number = 345L; B. long number = 0345;C. long number = 0345L; D. long number = 0x345L;4. Which layout manager is used when the frame is resized the buttonss position in the Frame might be changed? A. BorderLayout B. FlowLayoutC. CardLayoutD. GridLayout 5. Which are not Java primitive types? A. shortB. BooleanC. byteD. float 6. Given the following code:if (x0) System.out.println(first); else if (x-3) System.out.println(second); else System.out.println(third); Which range of x value would print the string second? A. x 0B. x -3C. x = -3D. x -3 7. Given the following code:public class Personint arr = new int10;public static void main(String a) System.out.println(arr1);Which statement is correct?A. When compilation some error will occur.B. It is correct when compilation but will cause error when running.C. The output is zero.D. The output is null.8. Short answer:The decimal value of i is 13, the octal i value is: A. 14B. 015C. 0x14D. 0129. A public member vairable called MAX_LENGTH which is int type, the value of the variable remains constant value 100. Use a short statement to define the variable.A. public int MAX_LENGTH=100;B. final int MAX_LENGTH=100;C. final public int MAX_LENGTH=100;D. public final int MAX_LENGTH=100.10. Which correctly create an array of five empty Strings?A. String a = , , , , , ;B. String a 5;C. String 5 a; D. String a = new String5; for (int i = 0; i 4)System.out.println(Test A);else if(val 9)System.out.println(Test B);else System.out.println(Test C);Which values of val will result in Test C being printed:A. val 920. Which of the following are valid definitions of an applications main ( ) method?A. public static void main( );B. public static void main( String args );C. public static void main( String args );D. public static void main( Graphics g );21. After the declaration:char c = new char100;what is the value of c50?A. 50B. C. u0032D. u000022. Which of the following statements assigns Hello Java to the String variable s ?A. String s = Hello Java;B. String s = Hello Java;C. new String s = Hello Java;D. String s = new String (Hello Java);23. If arr contains only positive integer values, what does this function do?public int guessWhat(int arr)int x = 0;for(int i = 0; i arr.length; i+)x = x arri ? arri : x;return x;A. Returns the index of the highest element in the arrayB. Returns true/false if there are any elements that repeat in the arrayC. Returns how many even numbers are in the arrayD. Returns the highest element in the array24. Which of the following are legal declarations of a twodimensional array of integers?A. int55 a = new int;B. int a = new int5,5;C. int a = new int 55;D. inta = new 5int5;25. If val = 1 in the code below:switch (val)case 1: System.out.print(P);case 2:case 3: System.out.print (Q) ;break;case 4: System.out.print(R);default: System.out.print (S);A. PB. PQC. QSD. PQRS26. Given the following code:1. public class Test 2. int m, n;3. public Test() 4. public Test(int a) m=a; 5. public static void main(String arg) 6. Test t1,t2;7. int j,k;8. j=0; k=0;9. t1=new Test();10. t2=new Test(j,k);11. 12. Which line would cause one error during compilation?A. line 3B. line 5C. line 6D. line 1027. For the code:m = 0;while( +m 2 )System.out.println(m);Which of the following are printed to standard output?A. 0B. 1C. 2D. 328. Consider the following code: What will happen when you try to compile it?public class InnerClasspublic static void main(Stringargs)public class MyInner A. It will compile fine.B. It will not compile, because you cannot have a public inner class.C. It will compile fine, but you cannot add any methods, because then it will fail to compile.D. It will compile fail.29. What is the result of executing the following code:public class Test public static void main(String args) String word = restructure; System.out.println(word.substring(2, 5); A. restB. esC. strD. st30. What will be written to the standard output when the following program is run? public class Test public static void main(String args) System.out.println(9 2); A. 11B. 7C. 18D. 0 31. When call fact(3), What is the result?int fact(int n) if(n=1) return 1; else return n*fact(n-1); A. 2B. 6C. 3D. 0 32. What is the result of executing the following code:String s=new String(abcdefg);for(int i=0;is.length();i+=2) System.out.print(s.charAt(i); A. acegB. bdfC. abcdefgD. abcd33. What is the result of executing the following code:publicclassTestpublicstaticvoidchangeStr(Stringstr)str=welcome;publicstaticvoidmain(Stringargs)Stringstr=12345;changeStr(str);System.out.println(str);Pleasewritetheoutputresult:A. welcomeB. 12345C. welcome12345D. 12345welcome34. What is the result of executing the following code:1.publicclassTest2.staticbooleanfoo(charc)3.System.out.print(c);4.returntrue;5.6.publicstaticvoidmain(Stringargv)7. inti=0;8. for(foo(A);foo(B)&(i2);foo(C)9. i+;10. foo(D);12.13. 14.Whatistheresult?A.ABDCBDCBB.ABCDABCDC.Compilationfails.D.Anexceptionisthrownatruntime.35. What will happen when you attempt to compile and run the following code?public final class Test4 class Inner void test() if (Test4.this.flag); else sample(); private boolean flag=false; public void sample() System.out.println(Sample); public Test4() (new Inner().test(); public static void main(String args) new Test4(); What is the result: A. Print out “Sample” B. Program produces no output but termiantes correctly. C. Program does not terminate. D. The program will not compile 36. What is the result of executing the following fragment of code:class Base Base() amethod(); int i = 100; public void amethod() System.out.println(Base.amethod(); public class Derived extends Base int i = -1; public static void main(String argv) Base b = new Derived(); System.out.println(b.i); b.amethod(); public void amethod() System.out.println(Derived.amethod(); A. Derived.amethod()B. Derived.amethod() -1100 Derived.amethod()Derived.amethod()C. 100D. Compile time error Derived.amethod()37. What is the result of executing the following code:public class Test String s1=menu; public static void main(String args) int z=2; Test t=new Test(); System.out.println(t.s1+z); A. menu2B. 2C. 2menuD. menu38. What is the result of executing the following code:public class Test implements A int x=5; public static void main(String args) Test c1 = new Test(); System.out.println(c1.x+A.k); interface A int k= 10;A. 5B. 10C. 15D. 10539. What is the result of executing the following code:import java.util.Arrays;public class Test public static void main(String unused) String str = xxx, zzz,yyy,aaa; Arrays.sort(str); int index=Arrays.binarySearch(str,zzz); if(index=-1) System.out.println(no); else System.out.println(yes); A. noB. xxxC. 0D. yes40. What is the result of executing the following code:int b=2, 3, 4, 5, 6, 7, 8; int sum=0; for(int i=0;ib.length;i+) for(int j=0;jbi.length;j+) sum+=bij; System.out.println(sum=+sum);A. 9B. 11C. 15D. 35 41. What is the result of executing the following code:public class Test static void leftshift(int i, int j) i=j; public static void main(String args) int i=4, j=2; leftshift(i,j); System.out.println(i); A. 2B. 4C. 8D. 1642. What is the result of executing the following code:public class Test int x=2; int y; public static void main(String args) int z=3; Test t=new Test(); System.out.println(t.x+t.y+z); A. 5B. 23C. 2D. 3 43. What is the result of executing the following fragment of code: boolean flag = false;if (flag = true) System.out.println(true); else System.out.println(false);A. trueB. falseC. An exception is raisedD. Nothing happens44. In the following applet, how many buttons will be displayed? import java.applet.*; import java.awt.*; public class Q16 extends Applet Button okButton = new Button(Ok); public void init() add(okButton); add(okButton); add(okButton); add(new Button(Cancel); add(new Button(Cancel); add(new Button(Cancel); add(new Button(Cancel); setSize(300,300); A. 1 Button with label Ok and 1 Button with label Cancel.B. 1 Button with label Ok and 4 Buttons with label Cancel.C. 3 Buttons with label Ok and 1 Button with label Cancel.D. 4 Buttons with label Ok and 4 Buttons with label Cancel.45. What is the result of executing the following code:1. class StaticStuff 2. static int x = 10;3.static x += 5; 4. public static void main(String args)5. System.out.println(x = + x);6. 7. static x /= 5; 8. A. x = 10B. x = 15C. x = 3D. x=546. What will appear in the standard output when you run the Tester class? class Tester int var; Tester(double var) this.var = (int)var; Tester(int var) this(hello); Tester(String s) this(); System.out.println(s); Tester() System.out.println(good-bye); public static void main(String args) Tester t = new Tester(5); A. helloB. good-bye C. hello followed by good-byeD good-bye followed by hello47. What letters are written to the standard output with the following code? class Unchecked public static void main(String args) try method(); catch(Exception e) static void method() try wrench(); System.out.println(a); catch(ArithmeticException e) System.out.println(b); finally System.out.println(c); System.out.println(d); static void wrench() throw new NullPointerException(); Select all valid answers.A. aB. bC. cD. d48. Given this code snippet:try tryThis();return; catch(IOException x1) System.out.println(exception 1);return; catch(Exception x2) System.out.println(exception 2);return; finally System.out.println(finally);what will appear in the standard output if tryThis() throws a IOException?A. exception 1 followed by finallyB. exception 2 followed by finallyC. exception 1 D. exception 2二、填空題(每空1分,共10分) 1. JVM指的是Java【1】。2. Java中的字符變量在內存中占【2】位(bit)。3. Java語言對簡單數據類型進行了類包裝,int對應的包裝類是【3】。4. 繼承性是面向對象方法的一個基本特征,它使代碼可【4】5. 抽象類中含有沒有實現的方法,該類不能【5】。6. 在Java的輸入輸出流中,數據從數據源流向數據目的地,流的傳送是【6】行的。7. 若類聲明時加上修飾符 final ,則表示該類不能有【7】。8. Java的類庫中提供Throwable類來描述異常,它有Error 和【8】兩個直接子類。9. 類中的某些方法通過類名就可以直接被調用,例如JOptionPane.showMessage Dialog(null,”按確定鍵退出”)中的showMessageDialog 方法,這種方法稱為【9】。10. Java 的線程調度策略是一種基于優先級的【10】式調度。三、寫出下面程序的功能或運行結果(每小題4分,共20分)1. 下面程序的功能是什么?public class Exam1 public static void main(String args) for(int i=1; i10; i+) for(int j=1; j=i; j+) System.out.print(j + * + i + = + j*i + ); if(j*i10)System.out.print( ); System.out.println(); 2. 下面程序的功能是什么?public class Exam2 public static void main(String args) int x = 2, y = 1, t; double sum = 0; for(int i=1; i=15; i+) sum = sum + (double)x/y; t = y; y = x; x = y + t; System.out.println(Sum= + sum);3. 下面程序的功能是什么?import java.util.*;public class lianxi29 public static void main(String args) Scanner s = new Scanner(System.in); int a = new int33;System.out.println(請輸入9個整數:); for(int i=0; i3; i+) for(int j=0; j3; j+) aij = s.nextInt(); System.out.println(
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030中國消炎藥行業供需趨勢及投資風險報告
- 2025至2030中國濃縮池刮泥機行業市場發展分析及發展趨勢預測與戰略投資報告
- 2025至2030中國橙濃縮汁市場產銷規模分析與消費前景預測報告
- WTO“綠箱”補貼視角下我國農業補貼法律制度研究
- 大班建構游戲中幼兒學習品質發展研究-以西寧市A幼兒園為例
- 雜原子摻雜CoFeLDH-MXene復合材料的制備及其電催化析氧性能研究
- 紫光股份連續并購價值創造效果研究-基于資源整合理論視角
- 農業生產管理流程優化協議
- 詞匯擴展與記憶法:人教版英語六年級上冊教學教案
- 珠寶首飾行業商業計劃書:2025年高端定制市場拓展策略
- 肺炎衣原體醫學課件
- 公司銷售清單
- 《多邊形的面積》課件
- 《行政執法基礎知識》課件
- 信息安全保密教育培訓課件
- 燈具安裝協議
- 工業機器人視覺20
- TL226 大眾試驗測試標準
- 毛澤東思想和中國特色社會主義理論體系概論(復旦大學)智慧樹知到課后章節答案2023年下復旦大學
- 關于退租的申請書
- 吳川市中醫院新增數字減影裝置(DSA)項目環境影響報告表
評論
0/150
提交評論