《Java基础练习二》由会员分享,可在线阅读,更多相关《Java基础练习二(62页珍藏版)》请在金锄头文库上搜索。
1、C 8. class A implements Runnableint i;public void run()tryThread.sleep(5000); i=10;catch(InterruptException e)public static void main(String args)trya=new A();Thread t=new Thread(a);t.start();14)int j=i;16)catch(Exception e)在第 14 行加上哪些代码才能保证在第 16 行时 j=10? (单选) A.wait(); B.t.wait(); C.t.join(); D.t.y
2、ield(); E.t.notify(); A 2. 考察以下陈述:陈述 A:属性定义类的特征。陈述 B:行为定义类所执行的动作。关于这些陈述,以下中哪个是正确的? A 两个陈述都为真。B 两个陈述都为假。C 陈述 A 为真,陈述 B 为假。D 陈述 A为假,陈述 B 为真。 (单选) (答题时限:00:00:30) D 3. 11. for (int i =0; i 3; i+) 12. switch(i) 13. case 0: break; 14. case 1: System.out.print(“one “); 15. case 2: System.out.print(“two “)
3、; 16. case 3: System.out.print(“three “); 17. 18. 19. System.out.println(“done”);What is the result? (单选) A.done B.one two done C.one two three done D.one two three two three done E.Compilation fails. A 4. 11. public void test(int x) 12. int odd = x%2; 13. if (odd) 14. System.out.println(“odd); 15.
4、else 16. System.out.println(“even”); 17. 18. Which statement is true? (单选) A.Compilation fails. B.“odd” will always be output. C.“even” will always be output. D.“odd” will be output for odd values of x, and “even” for even values. E.“even” will be output for add values of x, and “odd” for even value
5、s. A 5. 为把文件指针设置为文件内的特定位置,你将使用以下RandomAccessFile 类方法中哪个? (单选) (答题时限:00:00:30) A.void seek(long pos) B.long getFilePointer() C.long length() D.Byte readBytes(long) B 6. You want to limit access to a method of a public class to members of the same class. Which access accomplishes this objective? (单选)
6、A.public B.private C.protected D.transient E.default access D 7. Math类所在的包位置为()。 (单选) A.java.awt.*; B.java.io.* C.java.sql.*; D.java.lang.* B 8. 1.publicclassTest2.privatestaticfloatf=newfloat2;3.publicstaticvoidmain(Stringargs)4.System.out.println(“f0=“+f0);5.8. 1.publicclassTest2.privatestaticfloa
7、tf=newfloat2;3.publicstaticvoidmain(Stringargs)4.System.out.println(“f0=“+f0);5.6.Whatistheresult? (单选) A.f0=0 B.f0=0.0 C.Compilationfails. D.Anexceptionisthrownatruntime. C 1. 执行完下面的程序段后,k的值为( )。int k=0;label:for(int i=1;i3;i+)for(int j=1;j -j) 14. continue; 15. 16. while (i 0) x=1;switch(x)case 1:
8、 System.out.print(1);case 0: System.out.print(0);case 2: System.out.print(2);break;case 3: System.out.print(3);default:System.out.print(4);break; (单选) A.02 B.43 C.23 D.10 1. 考察客户程序内所写的以下代码片段: PrintStream out=new PrintStream(clientSocket.getOutputStream(); 为引用上面代码片段,考察以下陈述: 陈述 A:用PrintStream 对象从socket中读入。陈述 B:getOutputStream() 方法提供了对server socket输出流的引用,并使客户与server通信。 关于这些陈述,以下中哪个为真? (单选) (答题时限:00:00:30) A.陈述 A 为真,陈述 B 为假。 B.陈述 A为假,陈述 B 为真。 C.陈述 A和 B都为真。 D.陈述 A和 B都为假。 标准答案:B 2. class A implements Runnableint i;public void run()tryThread.sleep(5000); i=10;catch(Int