收藏 分享(赏)

Java程序设计基础本部(A).doc

上传人:dzzj200808 文档编号:2563374 上传时间:2018-09-22 格式:DOC 页数:10 大小:90.50KB
下载 相关 举报
Java程序设计基础本部(A).doc_第1页
第1页 / 共10页
Java程序设计基础本部(A).doc_第2页
第2页 / 共10页
Java程序设计基础本部(A).doc_第3页
第3页 / 共10页
Java程序设计基础本部(A).doc_第4页
第4页 / 共10页
Java程序设计基础本部(A).doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

1、装订线内不要答题,装订线外不要写姓名、学号、学院专业年级班签个人信息,违者试卷作0分处理考 点 号教 室 号姓 名学 院专 业年 级班 号学号(全号)湖 南 农 业 大 学 课 程 考 核 试 卷课 程 名 称 ( 全 称 ) : Java 程 序 设 计 基 础 ( 双 语 ) 课 程 代 码 : 20638B3考 核 时 间 : 2010 年 11 月 5 日 试 卷 号 : A考 核 对 象 : 信 息 工 程 07 1、 信 息 工 程 07 2大 题 号 一 二 三 四 五 六 七 八 九 十 总 分题 分 40 10 20 10 20得 分1. Given the file Fir

2、stClass.java:1: import java.*;2: public class FirstClass 3: public interface Second 4: abstract class SecondClass What error will the compiler likely generate? ( )A. Package java not found in import. B. None. The file will compile fine.C. Public interface Second must be defined in a file called “Sec

3、ond.java”.D. Public class FirstClass must be defined in a file called “FirstClass.java”.2. Which of the following class definitions are legal? ( )A. private class A B. final abstract class F C. abstract class E; D. public class C 3. Given the following code:1:public class Century implements Runnable

4、 2: public void run( ) 3: for(int year=1990; year2000; year+)4: try Thread.sleep(1000); 5: catch(InterruptedException e) 6: 7: System.out.println(“Happy new millennium!”) 8:class CountUp9: public static void main(String args)10: Century ourCentury = new Century( );11: /12:得 分I、 Choose one correct an

5、swer( Total 40 points, each question 2 points)You now wish to begin the thread from another class. Which is the proper code, placed in the class CountUp at line 11, to begin the thread( )A. Thread t=new Thread(ourCentury); B. Thread t=new Thread(this);t.start( ); t.start( );C. Thread t=new Thread(ou

6、rCentury); D. Thread t=new Thread(this);ourCentury.start( ); ourCentury.run( );4. Assuming the array is declared as a class member, which of the following will declare an array and initialize it with five numbers? ( ) A. Array a=new Array(5); B. int array; C. int array=new int5; D. int a =new int(5)

7、;5. Examine the following code:1: class StringLiteral2: public static void main(String args)3: String java= “Java”, va= “va”;4: System.out.print( java= “Java” );5: System.out.print( java=( “Ja”+va ) );6: System.out.print( java.equals( “Ja”+va );7: ( )A. true true true B. true false true C. true true

8、 false D. false true true 6. Complete the following sentence.finally clauses ( ).A. are executed only after a try block executes with no exceptionsB. are only executed if an exception is thrown but no matching catch clause is found.C. are always executed after try and catch blocks.D. are only execut

9、ed if a catch clause is executed in the current method. 7. Which of the following is not a benefit of encapsulation ? ( ) A. Clarity of code B. Code efficiency C. The ability to add functionality later on D. Modification requires less coding changes8. What does a Java programmer have to do in order

10、to release an object that is no longer needed?( ) A. Use the delete statement.B. Call the finalize( ) method for the object.C. Call System.gc( ).D. Nothing.9. Which of the following assignment is not correct? ( )A. double f = 11.1; B. double d = 5.3E12; C. double d = 3.14159; D. float d = 3.14. 10.

11、Given the uncompleted code of a class: 1: public class A2: public void baz( ) 3: System.out.println(“A”);4: public class B extends A5: public static void main(String args)6: A a=new B( );7: a.baz( );8: public void baz( )9: System.out.println(“B”);What will happen when you compile and run this progra

12、m? ( ) A. The program compiles, runs, and displays A in the standard output.B. The program compiles, runs, and displays B in the standard output.C. The program compiles, but throws a runtime exception.D. The program does not compile.11. Of the following objects, which can not have locks ?( )A. Threa

13、d objects B. Runnable Objects C. Primitive types D. Object objects 12. Given the following code: 1:import java.io.*; 2:public class Inventory3: public static void main(String args) throws IOException4: FileInputStream inFile= new FileInputStream(“surplus.dat”);5: DataInputStream inData= new DataInpu

14、tStream( inFile );6: String s= inData.readUTF( );7: System.out.println( s );8: inData.close( ); 9: Assume there is a file in the current directory called “ surplus.dat ” that contains a string of Unicode characters. What will happen if you attempt to compile and run this block of code? ( )A. The fil

15、e will not compile.B. The file will compile, but the class will generate an error when run.C. The class will run and overwrite the file called “ surplus.dat ” and then it will overwrite all data in the file.D. The class will run and read-in the first line of UTF characters as a string, then display

16、it on the screen.13. Assume you have an object that is used to contain two values: a and b. Which of the following methods in its class can prevent concurrent access problems? ( )A. public int read(int a, int b) return a+b; public void set(int a, int b) this.a=a; this.b=b;B. public synchronized int

17、read(int a, int b )return a+b;public synchronized void set(int a, int b) this.a=a; this.b=b;C. public int read(int a, int b) synchronized(a) return a+b; public void set(int a, int b) synchronized(b) this.a=a; this.b=b;D. public synchronized synchronized(this) int read(int a, int b )return a+b;public

18、 synchronized synchronized(this) void set(int a, int b) this.a=a; this.b=b;14. What is the default layout manager for a Panel container? ( )A. FlowLayout B. BorderLayout C. GridLayout D. CardLayout 15. Which modifier is NOT legal in Java? ( )A. private B. public C. protected D. protect16. Given the

19、following code: import java.awt.event.*; import java.awt.*; class Test implements . / do something Which listeners must be inserted in the place . to enable the program to pick up ActionEvent and WindowEvent? ( )A. ActionListener B. WindowListener C. ActionListener,WindowListener D. ActionListener,C

20、ontainerListener17. What is the main task that java command in JDK does? ( )A. Executes code B. Verifies code C. Loads code D. Compiles code18. Given the following command to run a correct class: java MyTest a b cWhich statement is true? ( )A. args0 = MyTest a b c B. args0 = MyTestC. args0 = a D. ar

21、gs1= “b”19. Given the following code:1: int I=0;2: outer:3: while( true )4: I+;5: inner:6: for (int j=0; j10; j+)7: I+=j;8: if ( j = 3)9: continue inner;10: break outer;11: continue inner;12: System.out.println ( “I is”+I );What will be the value of I when it is printed? ( )A. 1 ; B. 2; C. 3 ; D. 4

22、;20. Which statement can be compiled correctly: ( )A. import java.awt.*;package Mypackage;class Myclass B. import java.awt.*;class MyClasspackage MyPackage;C. /*This is a comment */package MyPackage;import java.awt.*;class MyClassD. None 1. Overidden methods may add exceptions from new hierarchies t

23、o the methods exception specification. ( ) 2. It is impossible to change the contents of a String variable. ( ) 3. Constructors must have the same name as the class itself. ( )4. An abstract class can be instantiated using the new operator. ( )5. A static method cannot be overridden. ( )6. All class

24、es share a single root, the Object class. ( )7. When two or more methods in the same class have the same name, they are said to be overloaded. ( )8. FileInputStream class allow you to create a new file to disk. ( )9. A File object encapsulates the properties of a file or a path, and also contain the

25、 methods for reading/writing data from/to a file. ( )10. A continue statement can only be used in a loop . ( )1. Function: Let severs communicate with clients. Please finish the following code.(Case-sensitive)Client code:trySocket client = new Socket(host, 2004);catch(IOException e)Server code:trySe

26、rverSocket server = new ServerSocket((1) );catch(IOException e)Socket socket = null;trysocket = (2) ; /waiting for communicating(3) ; /get inputstreamcatch(IOException e)finally(4) ; /close socket得 分II、 Decide correct or wrong( Total 20 points, each question 2 points, “ ”means right, “X” means wrong

27、)得 分 III、 Fill the following blanks( Total 20 points, each blank 2 points)2 Finish the following code.( Case-sensitive)import java.awt.Frame;import java.awt.Button;import java.awt.event.ActionListener;import java.awt.event. _(5)_ ;public class DemoFrame _(6)_ Framepublic DemoFrame()addButton(“Hello

28、world“); private void addButton(final String text)Button b=new Button(text);b.addActionListener( (7)_ ); add(b); public static void main(String args)(new DemoFrame().show();class MyListener _(8)_ ActionListener public void _(9)_ (ActionEvent e)System.out.println(“Button “+text+“ pressed“);3. Which m

29、ethod is used to signal the thread waiting on an object that they may continue?(10)_ is used to signal the thread waiting on an object that they may continue.1. Given the following code:public class WaitTestpublic static void main(String args)System.out.print(“1 ”);synchronized(args)System.out.print

30、(“2 ”);tryargs.wait();catch(InterruptedException e)System.out.print(“3 ”);得 分IV、 Write the results after code is executed.( Total 10 points, each question 5 points)What is the result of trying to compile and run this program:2. Given the following codeclass Bowl Bowl(int marker) System.out.println(“

31、Bowl(“ + marker + “)“); class Table static Bowl b1 = new Bowl(1);Table() System.out.println(“Table()“);static Bowl b2 = new Bowl(2);class Cupboard Bowl b3 = new Bowl(3);static Bowl b4 = new Bowl(4);Cupboard() System.out.println(“Cupboard()“);static Bowl b5 = new Bowl(5);public class StaticInitializa

32、tion public static void main(String args) System.out.println(“Creating new Cupboard() in main“);static Table t2 = new Table();static Cupboard t3 = new Cupboard(); Running the preceding code prints: 得 分 V、 programming( Total 20 points, no.1 8 points, no.2 12 points)1. Please write a Java applet progr

33、am to draw an oval. The center of the oval is (80,100) and width 50, height 70.import java.awt.*;public class DrawCircle extends Canvaspublic static void main(String args)new DrawCircle(); public DrawCircle()setSize(50, 50);public void paint(Graphics g) g.drawOval(80,100,50,70); 2. Please write a ja

34、va application program. Use “BufferedReader” class to read all data in file “hello.txt” and print them.湖南农业大学课程考核参考答案与评分标准课 程 名 称 ( 全 称 ) : Java 程 序 设 计 基 础 ( 双 语 ) 课 程 代 码 : 20638B3 考 核 学 期 : 20102011 年 秋 季 试 卷 号 : A考 核 对 象 : 2007 级 信 息 工 程 专 业 课 程 负 责 人 签 名 : 一 、 选 择 题 ( 本 大 题 共 40 分 , 每 小 题 2 分 )

35、1-5 C D A C B6-10 C B D D B11-15 C D B A D16-20 C A D A C二 、 判 断 题 ( 本 大 题 共 10 分 , 每 小 题 1 分 )1-5 6-10 三 、 填 空 题 ( 本 大 题 共 20 分 , 每 小 题 2 分 )1 2004 2. server.accept( ) 3.socket.getInputStream( )4. socket.close( ) 5.ActionEvent 或 者 * 6. extends7. new MyListener 8. implements 9. actionperformed 10. n

36、otify( )或 者 notifyAll( )四 、 程 序 阅 读 ( 本 大 题 共 10 分 , 每 小 题 5 分 )1 1 22. Bowl(1)Bowl(2)Table( )Bowl(4)Bowl(5)Bowl(3)Cupboard( )Creating new cupboard( ) in main五 、 程 序 设 计 ( 本 大 题 共 20 分 , 第 一 题 8 分 , 第 二 题 12 分 )1 import java.awt.*; 或 者 import javax.swing.*; ( 1 分 )import java.applet.Applet; ( 1 分 )p

37、ublic class Circle extends Applet ( 1 分 )public void paint(Graphics g) ( 1 分 )g.drawOval(55,65,50,70); ( 4 分 )2 import java.io.*; ( 1 分 )class Test ( 使 用 了 异 常 处 理 2 分 )public static void main(String args) throws IOExceptionString str; FileReader fr=new FileReader(“hello.txt“); ( 创 建 输 入 流 对 象 2 分 )BufferedReader bfr=new BufferedReader(fr); ( 创 建 缓 冲 流 2 分 )while(str=bfr.readLine()!=null) System.out.println(str); ( 读 取 文 件 信 息 并 输 出 4 分 )fr.close(); ( 关 闭 流 1 分 )

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报