《Java程序设计实用教程实验指导、实训与习题解析》 《Java语言程序设计》模拟试卷A.docx
Oava语言程序设计模拟试卷A(考试时间90分钟 总分100分)一、选择题(每题2.5分,共50分)1. Which of the following range of short is correct?A,-27- 27-lB.0-216-1C. 215-215-lD. 231 - 23I-12. Which declarations of identifiers are legal?A. $personsTwoUsers*pointthisB. _endline3. Which statement of assigning a long type variable to a hexadecimal value is correct?A. long number = 345L;long number = 0345;long number = 0345L;long number = 0x345L4. Which of the following fragments might cause errors?A. String s = "Gone with the wind*;String t = " good ”;String k = s + t;String s = "Gone with the wind'1;String t;t = s3 + "one”;String s = "Gone with the wind'*;String standard = s.toUpperCase();B. String s = nhome directory*'String t = s - "directory"5. Which are syntactically valid statement at/ point x?class Person private int a;public int change(int m) return m; )public class Teacher extends Person public int b;public static void main(String arg )Person p = new Person();Teacher t = new Teacher();int i;/ point x)A. i = m;B. i = b;C. i = p.a;D. i = p.change(30);E. i = t.b.6. Given the following code fragment:1) public void create() 2) Vector myVect;3) myVect = new Vector();4)Which of the following statements are true?A. The declaration on line 2 does not allocate memory space for the variable myVect.B. The declaration on line 2 allocates memory space for a reference to a Vector object.C. The statement on line 2 creates an object of class Vector.D. The statement on line 3 creates an object of class Vector.E. The statement on line 3 allocates memory space for an object of class VectorWhich are not Java keywords?A. TRUEB. sizeofC. constD.superE. voidWhich of the following statements are true?A. The equals() method determines if reference values refer to the same object.B. The = operator determines if the contents and type of two separate objects match.C. The equals() method returns true only when the contents of two objects match.D. The class File overrides equals() to return true if the contents and type of two separate objects match.7. Which statements about inheritance are true?A. In Java programming language only allows single inheritance.B. In Java programming language allows a class to implement only one interface.C. In Java programming language a class cannot extend a class and implement a interface together.D. In Java programming language single inheritance makes code more reliable.8.1) class Person 2) public void printValue(int i, int j) /*/ 3) public void printValue(int i)/*.*/ 4)5) public class Teacher extends Person 6) public void printValue。/*.*/ )7) public void printValue(int i) /*.*/8) public static void main(String args )9) Person t = new Teacher();10) t.printValue(lO);11)12)Which method will the statement on line 10 call?11) on line 212) on line 313) on line 614) on line 7Which are not Java primitive types?A. shortB. BooleanC. unitD. floatWhich keyword should be used to enable interaction with the lock of an object? The flag allows exclusive access to that object.A. transientB. synchronizedC. serializeD. staticWhich is the return type of the method main()?A. intB. voidC. booleanD. staticGiven the following code:if (x>0) System.out.println(nfirstn); else if (x>-3) System.out.println(Hsecondn); else System.out.println(nthirdn); Which range of x value would print the string "second”?A. x > 0B. x > -3C. x <= -3D. x <= 0 & x > -3Which statements about the garbage collection are true?A. The program developer must create a thread to be responsible for free the memory.B. The garbage collection will check for and free memory no longer needed.C. The garbage collection allow the program developer to explicity and immediately free the memory.D. The garbage collection can free the memory used java object at expect time.16> Given the uncompleted code of a class:class Person String name, department;int age;public Person(String n) name = n; public Person(String n, int a) name = n; age = a; public Person(String n, String d, int a) / doing the same as two arguments version of constructor/ including assignment name=n,age=a department = d;)Which expression can be added at the "doing the same as." part of the constructor?A. Person(n,a);B. this(Person(n,a);C. this(n,a);D. this(name,age).17> Which of the following statements about variables and their scopes are true?A. Instance variables are member variables of a class.B. Instance variables are declared with the static keyword.C. Local variables defined inside a method are created when the method is executed.D. Local variables must be initialized before they are used.18、public void test() try oneMethod();System.out.println(,'condition 1"); catch (ArraylndexOutOfBoundsException e) System.out.println(ncondition 2"); catch(Exception e) System.out.println(ncondition 3n); finally System.out.println(nfinallyn);)Which will display if oneMethod run normally?A. condition 1B. condition 2C. condition 3D. finally19> Given the following code:public class Test void printValue(int m)do System.out.println(nThe value isn+m);)while( m > 10 )public static void main(String arg |) int i=10;Test t= new Test();t.printValue(i);) ) Which will be output? A. The value is 8 B. The value is 9 C. The value is 10 D. The value is 1120 ,下面的有关声明的哪些叙述是对的。A.对原始数据类型例如boolean,byte的变量的声明不会为该变量分配内存空间。B.对原始数据类型例如boolean,byte的变量的声明将为之分配内存空间。C.非原始数据类型例如String,Vector的变量的声明不会为该对象分配内存。D.非原始数据类型例如String,Vector的变量的声明会为该对象分配内存。 二、填空题(20分)(1 )对象串行化可以很容易地扩展成支持Java对象的1,它提供了对象从流中重建的 补充方式.(2分)(2 ) Vector类的对象是通过capacity和capacity Increment两个值来改变集合的容量,其中 capacity表示集合最多能容纳的2 , capacityincrement表示每次增加多少容量,不是一个一 个增加.(3分)(3)下列程序的功能是判断某一年是否为闰年,请在横线处填入适当内容,使程序能够正确 运行.(5分)import java.io.*;public class Leap Year public static void main(String arge)throws IOException InputStreamReader ir;BufferdeReadwe in;ir=new InputStreamReader(System.in);in=new BufferedReader(ir);System.out.printin(“输入年份是:”); String s= 3 int year=lnteger.parselnt(s);if year % 4 = = 0 && year % 100! = 0 / year % 400 二= 0) (System, out. println(""+year+”年是闰年.”);) else (System, out. println("”+year+”年不是闰年."); ) )(4)下面程序对数组中每个元素赋值,然后按逆序输出.请在横线处填入适当内容,使程序 能正常运行.(5分)import java.io.*;public class ArrayTestpublic static void main(String args) int i;int a = new int5;for(i=0;i<5;i+)a=i;for( 4 i>=0;i-)System.out.println(Han+i+n=na); ) )(5)下列程序的功能是:输入一个姓名,程序运行后,输出“姓名Welcome you!”.例如, 输入“张三Welcome you !”.请在下面横线处填入正确的方法名,使程序可以正确运行.(5 分)import java,awt,*;import java.awt.event.;public class welcomenYoupublic static void main(String args) (new FrameInOut(); )class FramelnOut extends Frame implements ActionListener (Label prompt;TextField input,output;Button btnn;void FramInOut() (prompt=new Label(nPlease input your name*');input=new TextField(lO);output二new TextField(25);btnn=new Button(nClassn);5 (new FlowLayout();add(prompt);add(input);add(output);add(btnn);input.addActionListener(this);btnn.addActionListener(this);setSize(300.200);show();public void actionperformed(ActionEvent e)if(e.getSource() = = input)output.setText(input.getText()+nWelcome you!n); else (dispose();system.exit(O);)三、概念辨析题。(20分)1、解释术语:类;封装;继承.(6分)2、区别基本异常的分类?(8分)3、abstract class 和 interface 有什么区别? (6 分)四、程序设计题。(10分)当用户按或“小时,人为抛出一个算术异常,处理方式为打印出错信息(10分)