资源描述
考号:006 姓名:006
剩余时间:01:29:40
IP:192.168.0.26
网络连接: ●
(下)全国信息技术水平考试计算机程序设计技术水平证书(JAVA语言)考试试卷
第一大题:单选题
(30 分)
1. (1分)
下列论述中对的是( D )
(A) Java程序经编译后会产生machine code
(B) Java程序经编译后会产生byte code
(C) Java程序经编译后会产生DLL
(D) 以上都不对的
2. (1分)
下列说法中对的是( C )
(A) 类中构造办法声明不可省略
(B) 构造办法必要与类同名,构造办法返回值为void
(C) 构造办法在一种对象被new时执行
(D) 一种类只能定义一种构造办法
3. (1分)
JDBC惯用类和接口都包括在( A )包中。
(A) java.sql (B) java.awt (C) java.lang (D) java.swing
4. (1分)
执行下列程序后,C值是( C )
public class Test{
public static void main(String arg[]){
int a=0,c=0;
do{
--c;
a=a-1;
}while(a>0);
}
}
(A) 0 (B) 1 (C) -1 (D) 死循环
5. (1分)
若有int型public成员变量MAX_LENGTH,该值保持为常数100,则定义这个变量语句是( A )
(A) public int MAX_LENGTH=100
(B) final int MAX_LENGTH=100
(C) public const int MAX_LENGTH=100
(D) public final int MAX_LENGTH=100
6. (1分)
在程序中import,package,class浮现对的顺序是 ( )
(A) import package class
(B) package import class
(C) package class import
(D) import class package
7. (1分)
下列办法中可以用来创立一种新线程是( )
(A) 实现java.lang.Runnable接口并重写start()办法
(B) 实现java.lang.Runnable接口并重写run()办法
(C) 实现java.lang.Thread类并重写sleep()办法
(D) 实现java.lang.Thread类并重写start()办法
8. (1分)
下列程序输出成果是( )
public class Test{
public static void main(String[] args){
String a=new String("A");
String b=new String("B");
oper(a,b);
System.out.println(a+","+b);
}
static void oper(String c,String d){
c.concat("B");
d=c;
}
}
(A) A,A (B) 编译对的,运营时将产生错误 (C) A,B (D) AB,AB
9. (1分)
Java字符类型采用是Unicode编码方案,每个Unicode码占用( B )个比特位。
(A) 8 (B) 16 (C) 32 (D) 64
10. (1分)
下列程序段输出成果是( B )
int i = 9;
switch (i) {
default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two"); }
(A) default
(B) default
zero
(C) 程序编译出错
(D) 程序运营对的,但没有输出
11. (1分)
下列程序输出成果是( A )
public class Test{
public static void main(String args[]){
static int x[]=new int[15];
System.out.println(x[5]);
}
}
(A) 编译出错 (B) 编译通过,但运营时有错 (C) 输出0 (D) 输出null
12. (1分)
给出如下代码:
class Test{
private int m;
public static void fun(){
//some code
}
}
下列选项中,能使成员变量m 被函数fun()直接访问是 ( B )
(A) 将private int m 改为protected int m
(B) 将private int m 改为 public int m
(C) 将private int m 改为 static int m
(D) 将private int m 改为 int m
13. (1分)
给出如下代码,请问x处在什么范畴时将打印字符串“second” ( D )
if(x>5){System.out.println("first");}
else if(x>-5){ System.out.println("second");}
else {System.out.println("third");}
(A) x>5 (B) x>-5 (C) x<=-5 (D) x<=5 && x>-5
14. (1分)
一种线程run办法包括如下语句,假定线程没有被打断,则下列说法中对的是( B )
(1) try{
(2) sleep(10);
(3) }catch(InterruptedException e){ }
(A) 不能通过编译,由于在run办法中也许不会捕获到异常。
(B) 在第2行,线程将暂停运营,正好在10毫秒后继续运营。
(C) 在第2行,线程将暂停运营,最多在10毫秒内将继续运营。
(D) 在第2行,线程将暂停运营,将在10毫秒后某一时刻继续运营。
15. (1分)
关于如下代码,下列说法中对的是( D )
(1)abstract class AbstractOne{
(2) abstract int getInt();
(3) }
(4) public class Test extends AbstractOne{
(5) private int x=1;
(6) private int getInt(){
(7) return x; }
(8) }
(A) 编译成功
(B) 编译成功,但会导致运营时错误
(C) 编译无法通过,第2行有错
(D) 编译无法通过,第6行出错
16. (1分)
下列办法中不能成为办法public void add(int a){ }重载办法是( A )
(A) public int add(int a)
(B) public void add(long a)
(C) public void add(int a,int b)
(D) public void add(float a)
17. (1分)
下列程序执行后将有( C )个字节被写入到文献myfile.txt中
import java.io.*;
public class Test {
public static void main(String[] args){
try{
FileOutputStream fos=new FileOutputStream("myfile.txt");
DataOutputStream dos=new DataOutputStream(fos);
dos.writeInt(3);
dos.writeChar(1);
dos.close();
fos.close( );
}catch(IOException e) { }
}
}
(A) 3 (B) 5 (C) 6 (D) 不拟定,与软硬件环境有关
18. (1分)
下列程序段输出成果是( D )
public class Test{
static int i;
public static void main(String argv[]){
System.out.println(i);
}
}
(A) 有错误,变量i没有初始化 (B) null (C) 1 (D) 0
19. (1分)
A派生出子类B,B派生出子类C,并且在Java源代码中有如下声明:
(1)A a0=new A();
(2)A a1=new B();
(3)A a2=new C();
下列说法中对的是 ( D )
(A) 只有第1行能通过编译
(B) 第1、2行能通过编译,但第3行编译出错
(C) 第1、2、3行能通过编译,但第2、3行运营时出错
(D) 第1行、第2行和第3行声明都是对的
20. (1分)
下列说法中对的是( B )
(A) try语句可以单独存在,不需要其她附加语句
(B) try语句不能单独存在,背面必要要和catch或finally语句配合使用
(C) 在try语句背面catch语句只能有一句
(D) finally语句作用是用来完毕某些不能完毕工作
21. (1分)
当点击Applet中一种按钮控件时,下列哪个对象将会被创立( C )
(A) PaintEvent (B) TextEvent (C) ActionEvent (D) KeyEvent
22. (1分)
下列程序输出成果是( D )
class Parent{
String one, two;
public Parent(String a, String b){
one = a;
two = b;
}
public void print(){
System.out.println(one); }
}
public class Child extends Parent{
public Child(String a, String b){
super(a,b);
}
public void print(){
System.out.println(one + " to " + two);
}
public static void main(String arg[]){
Parent p = new Parent("south", "north");
Parent t = new Child("east", "west");
p.print();
t.print();
}
}
(A) south
east
(B) south to north
east to west
(C) south to north
east
(D) south
east to west
23. (1分)
若变量"result"是一种boolean型变量,则下列表达式合法是( B )
(A) result="True";
(B) if (result){ // do something... }
(C) if (result!= 0) { // so something... }
(D) result = 1
24. (1分)
下列类中可以作为FilterInputStream类构造办法参数是 ( C )
(A) FilterOutputStream类 (B) File类 (C) InputStream类 (D) RandomAccessFile类
25. (1分)
阅读下面代码片断
(1) String str = null;
(2) if ((str != null) && (str.length() > 10)){
(3) System.out.println("more than 10");
(4) }
(5) else if ((str != null) & (str.length() < 5)){
(6) System.out.println("less than 5");
(7) }
(8) else { System.out.println("end"); }
导致错误行号是( C )
(A) line 1 (B) line 2 (C) line 5 (D) line 8
26. (1分)
下列核心字中能制止一种类被继承是( A )
(A) final (B) protected (C) private (D) abstract
27. (1分)
若有如下类定义
abstract class Shape{
abstract void draw();
}
那么,在试图编译下面类定义时会发生什么状况 ( B )
class Square extends Shape{
}
(A) 都可以成功编译
(B) Shpe可以编译,而Square不能
(C) Square可以编译,而Shape不能
(D) Shape和Square都不能编译
28. (1分)
下列程序输出成果是 ( D )
class C1{
static int j=0;
public void method(int a){
j++;
}
}
class Test extends C1{
public int method(){
return ++j;
}
public void result(){
method(j);
System.out.println(j+method());
}
public static void main(String args[]){
new Test().result();
}
}
(A) 0 (B) 1 (C) 2 (D) 3
29. (1分)
下列程序输出成果是 ( D )
class Test{
static void change(String s){
s=s.replace('j','l');
}
public static void main(String args[]){
String s="java";
change(s);
System.out.println(s);
}
}
(A) 编译错误
(B) lava
(C) 运营时浮现异常
(D) java
30. (1分)
下列程序输出成果是( D )
public class Test{
static int I =0;
void fun(){
I++;
}
public static void main(String args[])
{
Test obj1=new Test();
Test obj2=new Test();
obj1.fun();
obj2.fun();
System.out.println(obj1.I);
}
}
(A) 编译错误 (B) 6 (C) 1 (D) 2
第二大题:实践题(编程题)
(70 分)
1. (20分)
程序功能:接受一种不大于1000正整数参数,返回3位字符串数据格式,整数位数局限性3位,前面补0。例如输入7,返回“007”,输入32,返回“032”,输入899,返回“899”等。
提示:
程序架构如下:
public class Test1{
/**
* 获得任意一种不大于1000正整数3位字符串格式
*/
public String GetStr(int n) {
}
public static void main(String args[]) {
Test1 t = new Test1();
System.out.println(test1.GetStr(7));
System.out.println(test1.GetStr(32));
System.out.println(test1.GetStr(899)); }
}
备注:考生按照系统提示目录保存试题文献,每道试题建立一种文献夹,文献夹名为题目编号。文献夹中文献命名参照提示所给程序架构。
例:第一题试题文献夹名为“1”,文献名为“Test1.java”,相应字节码文献为:Test1.class。
2. (25分)
程序功能:创立一种能装5个水果篮子,水果有苹果、橘子和香蕉,从篮子中一种一种把水果拿出来,并打印出该水果名称。
提示1:用数组来表达篮子。
提示2:创立水果类,该类中有一种抽象办法GetName,用来输出水果名称。
提示3:分别创立水果类3个子类:苹果、橘子和香蕉类,分别实现GetName办法。
程序架构如下:
public class Test2 {
public Test2() {
}
public static void main(String[] args){
fruit[] fruits = new fruit[5];
fruits[0] = new Apple();
fruits[1] = new Orange();
fruits[2] = new Banana();
fruits[3] = new Apple();
fruits[4] = new Orange();
for(int i=0;i<5;i++){
System.out.println(fruits[i].GetName());
}
}
}
//定义水果抽象类: fruit。
//定义水果类3个子类: Apple、Orange和Banana。
备注:考生按照系统提示目录保存试题文献,每道试题建立一种文献夹,文献夹名为题目编号。文献夹中文献命名参照提示所给程序架构。
例:第一题试题文献夹名为“1”,文献名为“Test1.java”,相应字节码文献为:Test1.class。
3. (25分)
程序功能:定义一种Customer类,其属性涉及客户编号(CustomerNo),客户名称(CustomerName),联系电话(Phone),地址(Address)。创立若干个该类对象并保存到文献中。程序再从文献循环读取对象直至文献末尾,并将每个对象属性显示在屏幕上。
提示1:使用对象流类实现对象数据读写功能。
提示2:循环读取文献中对象,通过捕获EOFException异常来判断与否文献末尾。
提示3:文献命名为“Customer.dat”
提示4:提示架构如下:
import java.io.*;
public class Test3 {
public Test3() {
}
public static void main(String[] args){
//写3个以上对象到文献
//从文献中循环读对象
}
}
class Customer implements java.io.Serializable{
String CustomerNo;
String CustomerName;
String Phone;
String Address;
public Customer(String no,String name,String phone,String address){
this.CustomerNo = no;
this.CustomerName = name;
this.Phone = phone;
this.Address = address;
}
}
显示成果如下:
备注:考生按照系统提示目录保存试题文献,每道试题建立一种文献夹,文献夹名为题目编号。文献夹中文献命名参照提示所给程序架构。
例:第一题试题文献夹名为“1”,文献名为“Test1.java”,相应字节码文献为:Test1.class。
展开阅读全文