Java程序设计基础本部(B).doc_第1页
Java程序设计基础本部(B).doc_第2页
Java程序设计基础本部(B).doc_第3页
Java程序设计基础本部(B).doc_第4页
Java程序设计基础本部(B).doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

装订线内不要答题,装订线外不要写姓名、学号、学院专业年级班签个人信息,违者试卷作0分处理考 点 号教 室 号姓 名学 院专 业年 级班 号学号(全号)湖南农业大学课程考核试卷课程名称(全称):Java程序设计基础(双语) 课程代码:30656B0考核时间:2008 年 月 日 试卷号: B考核对象:信息工程051、信息工程052大题号一二三四五六七八九十总分题分4020201010得分 得分I、Choose one correct answer(Total 40 points,each question 2 points)1. Which of the following are Java modifiers? (A )A. public B. true C. friendly D. transient2. Choose the valid identifier from those listed below. ( A) A. MyMethod B. 3byte C. 5_const D. true3.Which are legal declarations? ( A BD )A. short x ; B. short y; C. short y2 = 5; D. short z ; 4. Given the following code:class Top public Top(String s) System.out.print(B); public class Bottom2 extends Top public Bottom2(String s) System.out.print(D); public static void main(String args) new Bottom2(C); System.out.println( ); Whats the result when we compile and run the preceding code?( D )A. BD B. DB C. BDC D. Compilation fails5. What is the return value of the main() method in Java? ( D )A. String B. int C. char D. void6. Given the following, class X void dol() class Y extends X void do2() class Chrome public static void main(String args) X x1 = new X(); X x2 = new Y(); Y y1 = new Y(); / insert code here Which, inserted at line 8, will compile? ( C )A. x2.do2( ); B. (Y) x2. do2( ); C. (Y)x2).do2(); D.None of the above statements will compile.7. Which of the following assignments is NOT legal? ( A )A. float a = 2.0 B. double b = 2.0 C. int c = 2 D. long d = 28. Given the following command to run a correct class: java MyTest a b cWhich statement is true? ( D )A. args0 = MyTest a b c B. args0 = MyTestC. args0 = a D. args1= “b”9. Given the following code:switch (m) case 0: System.out.println(Condition 0); case 1: System.out.println(Condition 1); case 2: System.out.println(Condition 2); case 3: System.out.println(Condition 3);break; default: System.out.println(Other Condition);Which values of m will cause Condition 2 is output? ( A )A. 0,1 and 2 B. only 1 C. 3 D. 410. Which modifier is NOT legal in Java? ( D )A. private B. public C. protected D. protect11. Which method is used to define the execution body of a thread? ( C )A. start() B. init() C. run() D. main()12. Given the following class definition in one source file:class Base public Base () /. public Base ( int m ) /. protected void fun( int n ) /. public class Child extends Base/ member methodsWhich methods can be added into the Child class correctly? ( c )A. private void fun( int n ) /.B. void fun ( int n ) /. C. protected void fun ( int n ) /. D. public m() /. 13.Given the following code: Integer i = new Integer(42);Long m = new Long(42);Integer d = new Integer(42);Which expression evaluate to True? ( D )A. (i = =m) B. (i = = d) C. (d = m) D. (i.equals (d)14.Given the following code: public interface Runnable void run(); Which construct an anonymous inner class instance? ( c )A. Runnable r = new Runnable() ; B. Runnable r = new Runnable public void run(); C. System.out.println(new Runnable() (public void run() ); D. System.out.println(new Runnable(public void run() ); 15. Give the code fragment: switch(x) case 1:System.out.println(“Test 1”);break; case 2: case 3:System.out.println(“Test 2”);break; default:System.out.println(“end”); which value of x would cause “Test 2” to the output: ( BC )A. 1 B. 2 C. 3 D. default 16. When a subclass method has the same name,parameter list, and return type as a method in the parent class, this method is said to be what? ( D )A. Extended B. Overloaded C. Overextended D. Overridden17.public class Test public static void main(String args) new Test().foo(1,2); private void foo(int a, int b) System.out.println(“int”); private void foo(long a, int b) System.out.println(“long”); What will happen when you compile and run this program? ( A )A. The code will compile and run, and display int.B. The code will compile and run, and display long. C. The code will not compile.D. The code will compile,but throw a runtime exception when executed.18. Given the following code:public class Test public static void main(String args) new Test(4); public Test() System.out.println(“okay”); public Test(int i) / insert code here Which of the following lines of code should be inserted so that the output of the program is okay? ( D )A. super(); B. this; C. Test(); D. this();19. Given the following code:class Testpublic static void main(String args) String a = args1; String b = args2; String c = args3; If you will execute java Test cat dog sheep what will be the value of c? ( D )A. dog B. sheep C. Compilation Error D. Exception will occur20.Which statement is true about an inner class? ( D )A. It must be anonymous B. It can not implement an interface C. It is only accessible in the enclosing class D. It can access any final variables in any enclosing scope.得分II、Decide correct or wrong(Total 20 points,each question 2 points, “”means right, “X” means wrong)1.Java is a kind of object-oriented programming language. ( ) 2.Given: Stringstr=newString(abc); We create two objects using the preceding statement.( ) 3.Final class can not be extended.( )4.Abstract class and interface are the same.( )5. Constructors do not have a return type not even void. ( )6.All methods in a interface are abstract methods. ( )7.A static method cannot be overridden.( )8.A File object encapsulates the properties of a file or a path, it contains the methods for reading/writing data from/to a file. ( )9.Letter A and letter a are the same in Java.( )10.All classes share a single root, the Object class. ( )得分III、Fill the following blanks(Total 20 points,each blank except last two 2 points)1Finish the following code.( Case-sensitive)Function description:Read a line of file “myfile”Variable description:stream is an InputStream object corresponding to myfile S is a String objectInputStreamReader reader = new InputStreamReader ((1) stream );BufferedReader buffer = new BufferedReader( (2) reader );S =(3) buffer . (4) readLine() ; 2Display “Hello” every other 10 seconds.public class Test (5) implements Runnable public static void (6main) (String args) Test t=new Test(); (7) Thread tt=new Thread(t); tt. (8) start() ; public void run() for(;) try (9)Thread.sleep(10000) ; catch((10) InterruptedException e) Systm.out.println(“Hello”); 得分IV、Write the results after code is executed.(Total 10 points,each question 5 points)1.Given the following code:class Emu static String s = -; public static void main(String args) try throw new Exception(); catch (Exception e) try try throw new Exception(); catch (Exception ex) s += ic ; throw new Exception(); catch (Exception x) s += mc ; finally s += mf ; finally s += of ; System.out.println(s); Running the preceding code prints: ic mc mf of 2.Given the following code:public class WaitTest public static void main(String args) System.out.print(“1 ”); synchronized(args) System.out.print(“2 ”); try args.wait(); catch(InterruptedException e) System.out.prin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论