[08_09(1)]06网络班《Java程序设计》期末B卷(答案)
Java面向对象程序设计期末考试试卷B

7.设类B是类C的父类,下列声明对象x1 的语句不正确的是()。
(A) B x1=new B(); (B) B x1=new C();(C) C x1=new C(); (D) C x1=new B();8.给定下列程序代码,空格处应当填写的代码是:()class MyException extends Exception{void test(double x) throws MyException{if(x<0.0) throw___________;else System.out.println(Math.sqrt(x));}(A) Exception (B) MyException(C) ArithmeticException (D)DataFormatException9.定义字符串:String str=”abcdefg”;则str.indexOf(‘d’)的结果是()。
(A) ’d’(B) true (C) 3 (D) 410. 下面的说法不正确的是()。
(A) InputStream与OutputStream类通常是用来处理字节流,也就是二进制文件。
(B) Reader与Writer类则是用来处理字符流,也就是纯文本文件。
(C) Java中IO流的处理通常分为输入和输出两个部分。
(D) File类是输入/输出流类的子类。
11.当运行下面程序:java test 5 4。
下面程序的运行输出结果是:()public class test{public static void main(String[] args){System.out.println(args [1]);}}(A)0(B)5(C)编译出错(D)412.若下面指定的目录和文件名都存在,创建FileInputStream对象的语句不正确的是()。
(A) FileInputStream fis=new FileInputStream(“d:\\java\\1.txt”);(B) FileInputStream fis=new FileInputStream(“java/1.txt”);(C) FileInputStream fis=new FileInputStream(“d://java//1.txt”);(D) File file=new File(“1.txt”); FileInputStream fis=new FileInputStream(file);13.某java程序的类定义如下:public class MyClass extends BaseClass{}则该java源文件在存盘时的源文件名应为如下哪一种?()(A)myclass.java(B)MyClass.java(C)MYCLASS.JA V A(D)MyClass.class14.给出下面代码:1) class Parent {2) private String name;3) public Parent(){}4) }5) public class Child extends Parent {6) private String department;7) public Child() {}8) public String getValue(){ return name; }9) public static void main(String arg[]) {10) Parent p = new Parent();11) }12) }那些行将引起错误?( )(A)第3行(B)第6行(C)第7行(D)第8行15.下面()修饰符所定义的方法必须被子类所覆盖。
JAVA程序设计B卷答案

5.
在一个应用程序中有如下定义:int a[]={1,2,3,4,5,6,7,8,9,10}; 为了打印输出数组a的最 后一个元素,下面正确的代码是___B_____。 A. System.out.println(a[10]); C. System.out.println(a[a.length]); B. System.out.println(a[9]); D. System.out.println(a(9));
5
装 订 线
for(i=0;i<N;i++) //此 for 循环 4 分 { if (a[i]>=60) count=count+1; sum=sum+a[i]; } ave=sum/N; //计算平均分 1 分 printf(“count=%d,ave=%f”,count,ave); }
//输出 1 分,不局限于这种形式
评阅人
得分 一、单项选择题(本大题共 15 小题,每小题 2 分,共 30 分)
1. Java语言是____D_____。 A. 面向问题的解释型高级编程语言 C. 面向过程的编译型高级编程语言 2. 下列为合法类名的是___C_____。 A. class 3. B. 123Student C. GraduateStudent D. “类名” B. 面向机器的低级编程语言 D. 面向对象的解释型高级编程语言 线
10. 针对以下类定义,编译时出现语法错误的语句是___C_____。 class Animal { … } class Dog extends Animal { … } class Cat extends Animal { … } A. Animal animal = new Dog(); C. Dog dog = (Dog)new Cat(); B. Cat cat = (Cat)new Animal(); D. Cat cat = new Cat();
08-09Java期末试卷

1、Multiple Choice(20 point)Identify the letter of the choice that best completes the statement or answers the question.(1)The ____ statement identifies a block of statements that potentially may throw an exception.a. catchb. finallyc. throwd. try(2)Which method is used to invoke a constructor of the same class?a. this()b. constructor()c. super()d. class()(3)The ____ is a wildcard symbol to tell a program to import all necessary classes from a package.a. asteriskb. commac. periodd. semicolon(4)Which of the following is not a reference type in Java?a. arrayb. BufferedReaderc. floatd. String(5)The ____ class decodes bytes into characters.a. BufferedInputStreamb. BufferedReaderc. InputStreamReaderd. System.in(6)____ is a class used to display standard dialog boxes.a. Boxb. JFramec. JOptionPaned. JWindow(7)In java 2D, method _______of class Graphics2D sets the characteristics of a line used to draw ashape.a. setBackgroundb. setStrokec. setPaintd. translate(8) A ______ is needed to terminate recursion.a. recursion stepb. void return typec. break statementd. base case(9)What type of error will be produced first during the execution of the following code?a. ArrayIndexOutOfBoundsExceptionb. StringIndexOutOfBoundsExceptionc. cannot resolve symbold. NullPointerException(10)T he following is a list of classes / interfaces defined in Java's standard packages, List allinterfaces in the above list.a. Collectionb. Mathc. Listd. Threade. Runnablef. Collectionsg. Integer h. String2、True/False(10 points)Indicate whether the sentence or statement is true or false.(1)Multiple inheritances are not allowed in Java.(2)If I do not provide any arguments on the command line, then the String array of Main methodwill be null.(3)ng package is by default loaded internally by the JVM.(4)Importing a package imports the subpackages as well. e.g. Importing com.MyTest.* also importcom.MyTest.UnitTests.*.(5)The default value of an object reference declared as an instance variable is null.(6)If I write System.exit (0); at the end of the try block, the finally block will still execute.(7)When a thread is created and started, its initial state is runnable state.(8)The purpose of finalization is to give an unreachable object the opportunity to perform anycleanup processing before the object is garbage collected.(9)Static methods can be referenced with the name of the class rather than the name of a particularobject of the class.(10)T he local variables are not initialized to any default value, neither primitives nor objectreferences.3、Short answer(25 points)(1)Which method can you use to perform binary search for elements in an ArrayList or a(2)Difference between Vector and ArrayList?(2 points)(3)What is the difference between method overloading and method overriding? Can static methodsbe overridden? Can constructor be overridden?(6 points)(4)What is the purpose of garbage collection in Java, and when is it used?(2 points)(5)Explain how the Java interface works. What is the difference between an abstract class and aninterface? Produce examples of “implements” rela tionships.(3 points)(6)State the significance of public, private, protected, default modifiers both singly and incombination and state the effect of package relationships on declared items qualified by these modifiers.(4 points)(7)What are Checked and UnChecked Exception?(2 points)(8)Within a method m in a class C, isn't this.getClass() always C? (2 points)4、Completion(45 points)Complete each sentence or statement.(1)(2 points) An applet can also get references to all other applets on the same page using thegetApplets() method of (1) .(2)(5 points) Java applets begin execution with a series of three method calls: (2) ,(3) and (4) .The (5) method is invoked for an applet each time the userof a browser leaves an HTML page on which the applet resides. Every applet should extend class (6) .(3)(4 points) Consider the following classes:For the following code snippets(代码片段) from a to d, identify whether the code:●fails to compile (7)●compiles with a warning (8)●generates an error at runtime (9) or●none of the above (compiles and runs without problem.) (10)a. AnimalHouse<Cat> house = new AnimalHouse<Cat>();b. AnimalHouse<Cat> house = new AnimalHouse<Animal>();c. AnimalHouse house = new AnimalHouse<Animal>();d. AnimalHouse house = new AnimalHouse();house.setAnimal(new Dog());(4)(5 points) Assume the following:a = "abc";Give the values of the following expressions, or illegal.(11) "Tomorrow".substring(2,4)(12) a.length() + a(13) a.length() + a.startsWith("a")(14) "a".compareTo("c")(15) "a = \"" + a + "\""(5)(5 points)Write a method to copy a file from file1 to file2:(6)(6 points) Producer and Consumer are two threads which both implement interface Runnable.Complete the BlockingBufferTest class below to start the two threads.(7)(5 points) Establishing a simple server using stream sockets in java requires five steps.Step 1, to create an object, such as(20) server = new (20) (portNumber,queueLength);Step 2, the server listens indefinitely for an attempt by a client to connet. Such in(21) connection = server. (22) ;Step 3, to get the OutputStream and (23) objects that enable that server to communicate with the client by sending and receiving bytes.Step 4, is the processing phase.Step 5, when the transmission is complete, the server closes the connection by invoking the (24) method on the streams and on the Socket.(8)(4 points) Write method numInArray, as started below. numInArray should return the numberof times an even int parameter occurs in array A. For example, assume that array A is as shown below.[0] [1] [2] [3] [4] [5] [6]6 3 4 5 27 3then numInArray(A) should return 3 since 6, 4, and 2 are even.Complete method numInArray below.public static int numInArray(int[] A){// precondition: A will contain integers greater than zero// postcondition: returns the number of even integers found in A(25)}(9)(9 points) Complete the following program to do the following:a. Add buttons to the South region labeled "North", "South", "East", and "West".b. Create an X-shaped cross 10 pixels wide and 10 pixels high.c. Adds the cross so that its center is at the center of the graphics canvas.Once you have completed these steps, the display should look like this:d.Implement the actions for the button so that clicking on any of these buttons moves the cross20 pixels in the specified direction.。
《JAVA语言程序设计》期末考试试题及答案6

《JA V A语言程序设计》期末考试试题及答案6一、填空题1.定义类的保留字是(class ),定义接口的保留字是( interface )。
2.Socket通常也称为(套接字),用于描述( IP 地址) 和( 端口)。
3.线程的优先级在( 1 )至( 10)之间,数值越大( 任务越紧急)。
4.构造方法是一种特殊的成员方法,构造方法名与( 类名) 相同。
5.Java语言只允许单继承,指每个类只能有一个( 父类)。
6.Java源程序的扩展名是( .java ),经过编译后的程序的扩展名是(.class )。
7. 在一个时间只能由一个线程访问的资源称为( 临界资源) 。
访问临界资源的代码(临界代码)。
8. 在多线程系统中,多个线程之间有( 同步) 和( 互斥) 两种关系。
二、选择题1.关于选择结构下列哪个说法正确?()A.if语句和else语句必须成对出现B.if语句可以没有else语句对应C.switch结构中每个case语句中必须用break语句D.switch结构中必须有default语句2.while循环和do…while循环的区别是:()A.没有区别,这两个结构任何情况下效果一样B.while循环比do…while循环执行效率高C.while循环是先循环后判断,所以循环体至少被执行一次D.do…while循环是先循环后判断,所以循环体至少被执行一次3.关于for循环和while循环的说法哪个正确?()A.while循环先判断后执行,for循环先执行后判断。
B.while循环判断条件一般是程序结果,for循环的判断条件一般是非程序结果C.两种循环任何时候都不可以替换D.两种循环结构中都必须有循环体,循环体不能为空4.下列修饰符中与访问控制无关的是()A.private B.publicC.protected D.final5.void的含义:()A.方法没有返回值B.方法体为空C.没有意义 D.定义方法时必须使用6.return语句:()A.只能让方法返回数值B.方法都必须含有C.方法中可以有多句return D.不能用来返回对象7.关于对象成员占用内存的说法哪个正确?()A.同一个类的对象共用同一段内存B、同一个类的对象使用不同的内存段,但静态成员共享相同的内存空间C.对象的方法不占用内存D.以上都不对8.下列说法哪个正确?A.不需要定义类,就能创建对象B.对象中必须有属性和方法C.属性可以是简单变量,也可以是一个对象D、属性必须是简单变量9.下列说法哪个正确?()A、一个程序可以包含多个源文件B、一个源文件中只能有一个类C、一个源文件中可以有多个公共类D、一个源文件只能供一个程序使用10.关于方法main()的说法哪个正确?()A.方法main()只能放在公共类中B main()的头定义可以根据情况任意更改C.一个类中可以没有main()方法D.所有对象的创建都必须放在main()方法中11.构造函数何时被调用?()A、创建对象时B、类定义时C、使用对象的方法时D、使用对象的属性时12.抽象方法:()A、可以有方法体B、可以出现在非抽象类中C、是没有方法体的方法D、抽象类中的方法都是抽象方法13.关于继承的说法正确的是:()A、子类将继承父类所有的属性和方法。
java程序设计期末考试试题汇总及答案

java程序设计期末考试试题汇总及答案一、选择题(每题2分,共20分)1. 在Java中,下列哪个关键字用于声明一个类?A. classB. structC. functionD. interface答案:A2. Java中的异常处理机制是通过哪两个关键字实现的?A. try-catchB. if-elseC. switch-caseD. for-while答案:A3. 下列哪个选项是Java中合法的变量名?A. 2ndVariableB. _firstVariableC. variable-nameD. variable$name答案:C4. Java中,哪个关键字用于实现多态性?A. finalB. abstractC. interfaceD. implements答案:C5. 在Java中,下列哪个选项是正确的继承关系?A. 一个类只能继承一个类B. 一个类可以继承多个类C. 一个类可以继承多个接口D. 一个类不能继承任何类答案:A6. Java中,下列哪个关键字用于声明一个方法?A. classB. methodC. functionD. void答案:D7. 在Java中,下列哪个选项是正确的数组初始化方式?A. int[] array = new int[5];B. int array[] = {1, 2, 3};C. int[] array = {1, 2, 3};D. All of the above答案:D8. Java中,下列哪个选项是正确的接口定义?A. class InterfaceExample {}B. interface InterfaceExample {}C. abstract class InterfaceExample {}D. public class InterfaceExample {}答案:B9. 在Java中,下列哪个选项是正确的异常处理方式?A. try { ... } catch (Exception e) { ... }B. try { ... } catch (Error e) { ... }C. try { ... } finally { ... }D. All of the above答案:D10. Java中,下列哪个关键字用于声明一个枚举类型?A. enumB. enum classC. enum interfaceD. enum abstract答案:A二、填空题(每题2分,共20分)1. 在Java中,________关键字用于定义一个接口。
08—09年期末考试算法设计与分析试卷B及答案

附表、⑴ 证明:令F(N)=O(f),则存在自然数N1、C1,使得对任意的自然数N 1N ≥,有: 考试课程: 班级: 姓名: 学号: ------------------------------------------------- 密 ---------------------------------- 封 ----------------------------- 线 ---------------------------------------------------------F(N));(1N f C ≤……………………………..(2分)同理可令G(N)=O(g), 则存在自然数N2、C2,使得对任意的自然数N 2N ≥,有:G(N));(2N g C ≤ ……………………………..(3分)令 C3=max{C1,C2},N3=max{N1,N2},则对所有的N 3N ≥,有:F(N));(3)(1N f C N f C ≤≤G(N));(3)(2N g C N g C ≤≤ ……………………………..(5分)故有:O(f)+O(g)=F(N)+G(N))())()((3)(3)(3g f O N g N f C N g C N f C +=+=+≤因此有:O(f)+O(g)=O(f+g) ……………………………..(7分)⑵ 解:① 因为:;01033)103(lim 222=+-+∞→n n n n n n 由渐近表达式的定义易知:103322+n n 是的渐近表达式。
……………………………..(3分)② 因为:;0/12121)/121(lim =+-+∞→n n n 由渐近表达式的定义易知:21是21+1/n 的渐近表达式。
……………………………..(6分)2、解:经分析结论为:(1));5(log log 2+=n n θ………………………….(5分)(2))(log 2n n O =;………………………….(10分)(3))(log 2n n Ω=;………………………….(15分)3、解:用分治法求解的算法代码如下:int partition(float A[],int p,int r){int i=p,j=r+1;float x=a[p];while (1) {while(a[++i]<x&&i<r);while(a[--j]>x);if(i>=j) break;a[i]];[j a ↔ ……………………………..(4分)};a[p]=a[j];a[j]=x;return j; ……………………………..(7分)void Quicksort( float a[], int p, int r ){if( p<r) {int q=partition(a,p,r);……………………………..(10分)Quicksort(a,p,q-1);Quicksort(a,q+1,r);}};Quicksort(a,0,n-1);……………………………..(13分)4、解:用动态规划算法求解的算法代码如下:int lcs_len(char *a,char *b,int c[][N]){int m=strlen(a),n=strlen(b),i,j;for(i=0;i<=m;i++) c[i][0]=0;for(j=1;j<=n;j++) c[0][j]=0;……………………………..(4分)for(i=1;i<=m;i++)for(j=1;j<=n;j++)if(a[i-1]= =b[j-1]) c[i][j]=c[i-1][j-1]+1;else if(c[i-1][j]>=c[i][j-1])c[i][j]=c[i-1][j];else c[i][j]=c[i][j-1];……………………………..(7分)return c[m][n];……………………………..(8分)};char *build_lcs(char s[],char *a,char *b){int k,i=strlen(a),j=strlen(b),c[N][N];k=lcs_len(a,b,c);s[k]=’\0’;while(k>0){if(c[i][j]= =c[i-1][j]) i--;……………………………..(11分)else if(c[i][j]= =c[i][j-1]) j--;else{s[--k]=a[i-1];i--,j--;}}return s;……………………………..(15分)}5、解:int greedy(vecter<int>x,int n){int sum=0,k=x.size();for(int j=0;j<k;j++)if(x[j]>n){cout<<”No solution”<<endl;return -1;……………………………..(6分)for(int i=0,s=0;i<k;i++){s+=x[i];if(s>n){ sum++;s=x[i];} ……………………………..(9分) }return sum; ……………………………..(12分)}6、解:此题用动态规划算法求解:i nt dist( ){int m=a.size( );int n=b.size( );vector<int>d(n+1,0);for(int i=1;i<=n;i++) d[i]=i; ……………………………..(5分)for(i=1;i<=m;i++){int y=i-1;for(int j=1;j<=n;j++){int x=y;y=d[j];int z=j>1?d[j-1]:i; ……………………………..(10分)int del=a[i-1]= =b[j-1]?0:1;d[j]=min(x+del,y+1,z+1); ……………………………..(13分) }}return d[n]; ……………………………..(16分)}7、试用回溯法解决下列整数变换问题:关于整数i 的变换f 和g 定义如下:⎣⎦2/)(;3)(i i g i i f ==。
《JAVA程序设计》期末考试试题汇总及答案
/******************************ONE*******************************/一、单选择题1、编译Java Application源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为(B)。
A.javaB..classC.htmlD..exe2、设x=1,y=2,z=3,则表达式y+=z--/++x的值是(A)。
A.3B. 3.5C.4D.53、不允许作为类及类成员的访问控制符的是(C)。
A.publicB.privateC.staticD.protected4、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为(A)。
A.static void method()B.public void method()C.final void method()D.abstract voidmethod()二、填空题1、开发与运行Java程序需要经过的三个主要步骤为编辑源程序、编译生成字节码和解释运行字节码。
2、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用2字节内存空间,这样,无论是中文字符还是英文字符,都是占用2字节内存空间。
3、设x=2,则表达式(x)/3的值是0。
4、若x=5,y=10,则x<y和x>=y的逻辑值分别为true和false。
5、抽象(abstract)方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。
最终(final)方法是不能被当前类的子类重新定义的方法。
6、创建一个名为MyPackage的包的语句是package MyPackage;,该语句应该放在程序的位置为:应该在程序第一句。
7、设有数组定义:int MyIntArray[]={10,20,30,40,50,60, 70};则执行以下几个语句后的输出结果是120。
《JAVA语言程序设计》期末考试试题及答案6(应考必备题库)
《JAVA 语言程序设计》期末考试试题及答案6(应考必备题库)一、填空题1.定义类的保留字是(class ),定义接口的保留字是(interface ) 2.Socket 通常也称为(套接字),用于描述(IP 地址)和(端口) 3.线程的优先级在( 1 )至(10 )之间,数值越大(任务越紧急)。
1.定义类的保留字是(class ),定义接口的保留字是(interface )。
2.Socket 通常也称为(套接字),用于描述(IP 地址)和(端口)。
3.线程的优先级在( 1 )至(10 )之间,数值越大(任务越紧急)。
4.构造方法是一种特殊的成员方法,构造方法名与(类名)相同。
5. Java语言只允许单继承,指每个类只能有一个(父类)。
6. Java源程序的扩展名是(.java ),经过编译后的程序的扩展名是(.class )。
7. 在一个时间只能由一个线程访问的资源称为(临界资源)。
访问临界资源的代码(临界代码)。
8. 在多线程系统中,多个线程之间有(同步)和(互斥)两种关系。
二、选择题1. 关于选择结构下列哪个说法正确?()A. if 语句和else 语句必须成对出现B. if 语句可以没有else 语句对应C. switch结构中每个case语句中必须用break语句D. switch结构中必须有default语句2. while循环和do…while循环的区别是:()A .没有区别,这两个结构任何情况下效果一样B. while循环比do…while循环执行效率高C. while 循环是先循环后判断,所以循环体至少被执行一次D . do…while循环是先循环后判断,所以循环体至少被执行一次3.关于for 循环和while 循环的说法哪个正确?()A.while 循环先判断后执行,for 循环先执行后判断。
B.while 循环判断条件一般是程序结果,for 循环的判断条件一般是非程序结果C •两种循环任何时候都不可以替换D. 两种循环结构中都必须有循环体,循环体不能为空4.下列修饰符中与访问控制无关的是()A. private C. protected B.public D.final5. void 的含义:( )A.方法没有返回值B.方法体为空C.没有意义D. 定义方法时必须使用6 .return 语句:( )A .只能让方法返回数值B.方法都必须含有C .方法中可以有多句return D.不能用来返回对象7.关于对象成员占用内存的说法哪个正确?()A•同一个类的对象共用同一段内存B、同一个类的对象使用不同的内存段,但静态成员共享相同的内存空间C •对象的方法不占用内存D.以上都不对8.下列说法哪个正确?A .不需要定义类,就能创建对象B. 对象中必须有属性和方法C. 属性可以是简单变量,也可以是一个对象D. 属性必须是简单变量9.下列说法哪个正确?()A、一个程序可以包含多个源文件B、一个源文件中只能有一个类C、一个源文件中可以有多个公共类D、一个源文件只能供一个程序使用10.关于方法ma in ()的说法哪个正确?(A •方法main ()只能放在公共类中B ma in()的头定义可以根据情况任意更改C • 一个类中可以没有main()方法D .所有对象的创建都必须放在 mai n()方法中11.构造函数何时被调用? ( )A 、创建对象时c 、使用对象的方法时12. 抽象方法: ( )A 、 可以有方法体B 、 可以出现在非抽象类中C 、是没有方法体的方法D 、抽象类中的方法都是抽象方法13.关于继承的说法正确的是: ( )A 、 子类将继承父类所有的属性和方法。
JAVA程序设计期末考试题(多套含答案)
《JA V A程序设计》期末考试试题(五)一、单选题1、当某一线程正处于休眠状态,而另一个线程用Thread 类中的interrupt() 方法中断它时,抛出的异常类型是()。
A) IOException B) RuntimeExceptionC) InterruptedException D) ClassNotFoundException2、下面的程序段的功能是( )。
File file1=new File("d:\\xxx\\yyy\\zzz");file1.mkdirs();A)在当前目录下生成子目录:\xxx\yyy\zzz B)生成目录:e:\xxx\yyy\zzz C)在当前目录下生成文件xxx.yyy.zzz D)以上说法都不对3、应用程序的main方法中有以下语句,则输出的结果是( )。
String s = "xxxxxxxxxxxxxxx#123#456#zzzzz";int n = s.indexOf("#");int k = s.indexOf("#", n+1);String s2 = s.substring(n+1, k);System.out.println(s2);A) 123456 B) 123 C) xxxxxxxxxxxxxxx D) zzzzz4、关于下面的程序Test.java说法正确的是( )。
public class Test {String x="1";int y;public static void main(String args[]) {int z=2;System.out.println(x+y+z);}}A)3 B)102 C) 12 D)程序有编译错误5、应用程序的main方法中有以下语句,则输出的结果是( )。
int b[][]={{1, 1, 1}, {2,2}, {3}};int sum=0;for(int i=0; i<b.length; i++) {for(int j=0; j<b[i].length; j++) {sum+=b[i][j];}}System.out.println("sum="+sum);A) 10 B)6 C) 9 D) 136、应用程序的main方法中有以下语句,则执行后输出的结果是( )。
(完整word版)《JAVA语言程序设计》期末考试试题及答案6(应考必备题库)
《JAVA 语言程序设计》期末考试试题及答案6(应考必备题库)一、填空题1.定义类的保留字是(class ),定义接口的保留字是(interface ) 2.Socket 通常也称为(套接字),用于描述(IP 地址)和(端口) 3.线程的优先级在( 1 )至(10 )之间,数值越大(任务越紧急)。
1.定义类的保留字是(class ),定义接口的保留字是(interface )。
2.Socket 通常也称为(套接字),用于描述(IP 地址)和(端口)。
3.线程的优先级在( 1 )至(10 )之间,数值越大(任务越紧急)。
4.构造方法是一种特殊的成员方法,构造方法名与(类名)相同。
5. Java语言只允许单继承,指每个类只能有一个(父类)。
6. Java源程序的扩展名是(.java ),经过编译后的程序的扩展名是(.class )。
7. 在一个时间只能由一个线程访问的资源称为(临界资源)。
访问临界资源的代码(临界代码)。
8. 在多线程系统中,多个线程之间有(同步)和(互斥)两种关系。
二、选择题1. 关于选择结构下列哪个说法正确?()A. if 语句和else 语句必须成对出现B. if 语句可以没有else 语句对应C. switch结构中每个case语句中必须用break语句D. switch结构中必须有default语句2. while循环和do…while循环的区别是:()A .没有区别,这两个结构任何情况下效果一样B. while循环比do…while循环执行效率高C. while 循环是先循环后判断,所以循环体至少被执行一次D . do…while循环是先循环后判断,所以循环体至少被执行一次3.关于for 循环和while 循环的说法哪个正确?()A.while 循环先判断后执行,for 循环先执行后判断。
B.while 循环判断条件一般是程序结果,for 循环的判断条件一般是非程序结果C •两种循环任何时候都不可以替换D. 两种循环结构中都必须有循环体,循环体不能为空4.下列修饰符中与访问控制无关的是()A. private C. protected B.public D.final5. void 的含义:( )A.方法没有返回值B.方法体为空C.没有意义D. 定义方法时必须使用6 .return 语句:( )A .只能让方法返回数值B.方法都必须含有C .方法中可以有多句return D.不能用来返回对象7.关于对象成员占用内存的说法哪个正确?()A•同一个类的对象共用同一段内存B、同一个类的对象使用不同的内存段,但静态成员共享相同的内存空间C •对象的方法不占用内存D.以上都不对8.下列说法哪个正确?A .不需要定义类,就能创建对象B. 对象中必须有属性和方法C. 属性可以是简单变量,也可以是一个对象D. 属性必须是简单变量9.下列说法哪个正确?()A、一个程序可以包含多个源文件B、一个源文件中只能有一个类C、一个源文件中可以有多个公共类D、一个源文件只能供一个程序使用10.关于方法ma in ()的说法哪个正确?(A •方法main ()只能放在公共类中B ma in()的头定义可以根据情况任意更改C • 一个类中可以没有main()方法D .所有对象的创建都必须放在 mai n()方法中11.构造函数何时被调用? ( )A 、创建对象时c 、使用对象的方法时12. 抽象方法: ( )A 、 可以有方法体B 、 可以出现在非抽象类中C 、是没有方法体的方法D 、抽象类中的方法都是抽象方法13.关于继承的说法正确的是: ( )A 、 子类将继承父类所有的属性和方法。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2008-2009学年第一学期《Java 语言程序设计》试卷(B 卷) 院系:计算机 年级:2006 专业:计算机科学技术 班级: 学号: 姓名:
2、此试卷适用班级:计算机本科专业。
一、判断题,对的打[√]、错的打[╳]
:(10分,每小题2分) 1. 一个".java"源文件中可以包括多个公共类。
(╳) 2. Java 中的char 型变量中能存贮一个中文汉字。
(√) 3. 可以设计继承String 类的Java 子类。
(╳) 4. Java 中的数组没有length()这个方法,但有length 的属性,而String 有length()这个方法。
(√) 5. Java 中wait()方法用来暂时中止执行的线程,在睡眠后,线程将进入就绪状态。
(╳) 二、单选择题:(20分,每小题2分) 1.下列语句哪一个正确( B )
A . Java 程序经编译后会产生machine code
B . Java 程序经编译后会产生byte code
C . Java 程序经编译后会产生DLL
D . 以上都不正确
2.Java 为移动设备提供的平台是( A )
A . J2ME
B . J2SE
C . J2EE
D . JDK5.0
————————————装————————————————订
————————————————
线————————
3.编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( B )。
A. .java
B. .class
C. .html
D. .exe
4.执行如下程序代码
a=2;c=1;
do{
++c;
--a;
}while(a>0);
后,C的值是(A )
A.3 B.2 C.1 D.死循环
5.下列各选项中属于合法标识符的是( D )。
A.myid/2 B.+void C.5D. _vacl
6.下列语句中,属于多分支语句的是( B )
A.if语句B.switch语句
C.do while语句D.for语句
7.设 x = 2 , y = 4 , z = 3,则表达式 y+=z--/++x 的值是( D )。
A. 3
B. 3. 5
C. 4
D. 5
8.下列哪种说法是正确的(D )
A.实例方法可直接调用超类的实例方法
B.实例方法可直接调用超类的类方法
C.实例方法可直接调用其他类的实例方法
D.实例方法可直接调用本类的类方法
9.JDK中,用(B )命令对其源文件进行编译,生成字节码文件。
A. java.exe
B. javac.exe
C. javadoc.exe
D. javap.exe
10.下列哪一种叙述是正确的( C )
A. abstract修饰符可修饰字段、方法和类;
B.抽象方法的body部分必须用一对大括号{ }包住;
C . 声明抽象方法不可写出大括号;
D . 声明抽象方法,大括号可有可无;
三、填空题:(20分,每空2分) 1.如果一个Java Applet 程序文件中定义有3个类,则使用Sun 公司的JDK 编译器 javac.exe 编译该源程序文件将产生 3 个文件名与类名相同而扩展名为 .class 的字节码文件。
2. 如果想要创建一个名为TestPackage 的包,则其语句应该是 package TestPackage ; ,该语句应该放在程序的位置为 应该在程序第一句 。
3.在Java 程序中,通过类的定义只能实现 单 重继承,但通过接口的定义可以实现 多 重继承关系。
4.如果一个Java Applet 源程序文件只定义有一个类,该类的类名为MyFirstApplet ,则存储该源程序的文件名必须为 MyFirstApplet.java 。
5.在一个类的内部嵌套定义的类称为 内部类(Inner Class ) 。
四、简述题:(24分,每小题8分) 1.在java 中如果声明一个类为final ,表示什么意思? 解:final 是最终的意思,final 可用于定义变量、方法和类但含义不同,声明为final 的类不能被继承。
2.简述Java 中的异常处理机制的简单原理和应用。
解:当JAVA 程序违反了JAVA 的语义规则时,JAVA 虚拟机就会将发生的错误表示为一个异常。
违反语义规则包括2种情况:一种是JAVA 类库内置的语义检
查,例如数组下标越界,会引发IndexOutOfBoundsException ,访问null 的对象时会引发NullPointerException ;另一种情况就是JAVA 允许程序员扩展这种语义检查,程序员可以创建自己的异常,并自由选择在何时用throw 关键字引发异常;所有的异常都是ng.Thowable 的子类。
3.接口有什么优点?
————————————装
————————————————
订————————————————
线————————
解:接口有以下优点:
1)接口只是一个框架而没有实现,因此在接口定义时不需要考虑接口中的方法如何实现;
2)利用接口可达到实现多继承的目地;
3)可以在不暴露对象的类的前提下,暴露对象的编程接口;
4)不用强迫类关系在无关类中截获相似处(采用适配器就可以了);
5)声明想执行的一个或多个方法。
五、程序分析题:写出下列程序完成的功能(16分,每小题8分)
1. import java.awt.*;
public class Test
{ public static void main(String args[])
{ new FrameOut(); }
}
class FrameTest extends Frame
{ Button btn;
FrameTest ( )
{ super("按钮测试");
btn = new Button("请按下我");
setLayout(new FlowLayout( ));
add(btn);
setSize(300,200);
show( );
}
}
解:创建一个标题为"按钮测试"的窗框,窗框中显示有"请按下我"字样的按钮。
2.写出下列程序完成的功能。
public class CountTest
{ public static void main( String args[ ])
{ int S = 0 ;
for ( int i = 1 ; i <= 100 ; i + + ) S += i ;
System.out.println( "S="+S );
}
}
解:计算 1+2+3+...+100 的值。
六、编程题:(10分) 下面是一个图像缩放程序,请按要求填写下划线部分的语句。
import java.applet.*; import java.awt.*; public class Test9_3 extends Applet{ Image img; public void init(){ img=getImage(getCodeBase(),"disk.gif"); } public void paint(Graphics g){ int w=img.getWidth(this); int h= ① ; //读取图片的高度 g.drawImage(img,20,40,this); g. ② ; //将图片缩小1/2显示
g. ③ ; //将图片扩大1倍显示 }
}
//注:①语句得4分,②③每条语句得3分; 解:① img.getHeight(this);
② drawImage(img,100,100,w/2,h/2,this); ③ drawImage(img,160,10,w*2,h*2,this);
————————————装
————————————————订
————————————————
线————————。