资源描述
教育部教育管理信息中心
第二届全国ITAT教育工程就业技能大赛预赛试题
Java程序设计(A卷)
姓名:____________________ 准考证号:_______________________
题号
一
二
三
总分
得分
注意:在指定的路径下创建以姓名和准考证号命名的文件夹,并将试题答案存放在以题号命名的子文件夹中。凡未按照要求将试题存放在相应文件夹中的考生成绩一律作废。
一.选择题(每道题3分,共45分)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(1)Java语言具有许多优点和特点,下列选项中,哪个反映了Java程序并行机制的特点?
A、安全性 B、多线性 C、跨平台 D、可移植
(2)Character流与Byte流的区别是
A、每次读入的字节数不同 B、前者带有缓冲,后者没有
C、前者是块读写,后者是字节读写 D、二者没有区别,可以互换使用
(3)监听事件和处理事件
A、都由Listener完成 B、都由相应事件Listener处登记过的构件完成
C、由Listener和构件分别完成 D、由Listener和窗口分别完成
(4)Applet可以做下列哪些操作?
A、读取客户端文件 B、在客户端主机上创建新文件
C、在客户端装载程序库 D、读取客户端部分系统变量
(5)下列哪个属于容器的构件?
A、JFrame B、JButton C、JPanel D、JApplet
(6)以下声明合法的是( )
A、default String s; B、public final static native int w( )
C、abstract double d; D、abstract final double hyperbolicCosine( )
(7)关于以下application的说明,正确的是( )
1. class StaticStuff
2. {
3. static int x=10;
4. static { x+=5;}
5. public static void main(String args[ ])
6. {
7. System.out.println(“x=” + x);
8. }
9. static { x/=3;}
10. }
A、4行与9行不能通过编译,因为缺少方法名和返回类型
B、9行不能通过编译,因为只能有一个静态初始化器
C、编译通过,执行结果为:x=5
D、编译通过,执行结果为:x=3
(8)关于以下程序代码的说明正确的是( )
1.class HasStatic{
2. private static int x=100;
3. public static void main(String args[ ]){
4. HasStatic hs1=new HasStatic( );
5. hs1.x++;
6. HasStatic hs2=new HasStatic( );
7. hs2.x++;
8. hs1=new HasStatic( );
9. hs1.x++;
10. HasStatic.x- -;
11. System.out.println(“x=”+x);
12. }
13. }
A、 5行不能通过编译,因为引用了私有静态变量
B、 10行不能通过编译,因为x是私有静态变量
C、 程序通过编译,输出结果为:x=103
D、 程序通过编译,输出结果为:x=102
(9)以下选项中循环结构合法的是( )
A、while (int i<7)
{ i++;
System.out.println(“i is “+i);
}
B、 int j=3;
while(j)
{ System.out.println(“ j is “+j);
}
C、int j=0;
for(int k=0; j + k !=10; j++,k++)
{ System.out.println(“ j is “+ j + “k is”+ k);
}
D、 int j=0;
do{
System.out.println( “j is “+j++);
if (j = = 3) {continue loop;}
}while (j<10);
(10)类Test1定义如下:
1.public class Test1{
2. public float aMethod(float a,float b){ }
3.
4.}
将以下哪种方法插入行3是不合法的。( )
A、public float aMethod(float a, float b,float c){ }
B、public float aMethod(float c,float d){ }
C、public int aMethod(int a, int b){ }
D、private float aMethod(int a,int b,int c){ }
(11)类Test1、Test2定义如下:
1. public class Test1
2.{ public float aMethod(float a,float b) throws
3. IOException { }
4. }
5. public class Test2 extends Test1{
6.
7.}
将以下哪种方法插入行6是不合法的。( )
A、float aMethod(float a,float b){ }
B、public int aMethod(int a,int b)throws Exception{ }
C、public float aMethod(float p,float q){ }
D、public int aMethod(int a,int b)throws IOException{ }
(12)关于以下程序段,正确的说法是( )
1. String s1=”abc”+”def”;
2. String s2=new String(s1);
3. if(s1= =s2)
4. System.out.println(“= = succeeded”);
5. if (s1.equals(s2))
6. System.out.println(“.equals() succeeded”);
A、行4与行6都将执行 B、行4执行,行6不执行
C、行6执行,行4不执行 C、行4、行6都不执行
(13)以下说法哪项是正确的( )
1.class MyListener
2.extends MouseAdapter implements MouseListener{
3. public void mouseEntered(MouseEvent mev)
4. { System.out.println("Mouse entered."); }
5. }
A、以上代码可通过编译
B、不能通过编译,因为没有实现MouseListener接口中的所有方法
C、不能通过编译,因为类头定义不能分行
D、能通过编译,若组件用该类作为Mouse的监听者并且接收了mouse-exited事件,则在执行过程中会抛出异常
(14)关于以下程序段的说法,正确的是( )
1.class MyListener implements
2. ActionListener,ItemListener{
3. public void actionPerformed(ActionEvent ae){
4. System.out.println("Action");}
5. public void itemStateChanged(ItemEvent ie){
6. System.out.println("Item");
7. }
8.}
A、可通过编译
B、第2行产生编译错误
C、第3行产生编译错误
D、第5行产生编译错误
(15)通过调用 new List(10,false)创建一个列表,以下关于该列表的说法哪项是错误的。( )
A、该列表不支持复选 B、该列表有10个选项
C、根据需要该列表可能有垂直滚动条 D、该列表支持10个可见选项
二.写出以下程序的运行结果。(每道题10分,共30分)
1.写出以下程序的运行结果。
class OverloadDemo{
void testOverload( int i ){
System.out.println(“int”); }
void testOverload(String s){
System.out.println(“String”); }
public static void main(String args[ ]){
OverloadDemo a=new OverloadDemo ( );
char ch=’x’;
a.testOverload(ch); }
}
2.阅读以下程序,写出输出结果。
class First{
public First(){
aMethod(); }
public void aMethod(){
System.out.println(“in First class”);}
}
public class Second extends First{
public void aMethod(){
System.out.println(“in Second class”);}
public static void main(String[ ] args){
new Second( ); }
}
3.写出以下程序的运行结果。
import java.io.*;
public class UseLabel
{ public static void main(String[] args)
{Loop:
for(int i=2; i<10; i++)
{ for(int j=2;j<i;j++)
if( i%j == 0) continue Loop;
System.out.print(i+" "); } }
}
三.编程题(45分)
1.编写一个Java程序要求:开启一个文本文件,一次读取其内的一行文本。令每一行形成一个String,并将读出的String对象置于LinkedList中。请以相反次序印出LinkedList内的所有文本行。
答案:
Java程序设计B卷评分标准
一:选择题:
1~5CDCCD 6~10CBDDB 11~15CCAAC
二:程序阅读
(1) 1234 (2) in Second class (3)abdcbdcb
三:编程题
1.
import java.io.*;
import java.util.*;
public class E01_FileIntoList {
// Report all exceptions to console:
public static void main(String args[])
throws Exception {
LinkedList lines = new LinkedList();
BufferedReader in =
new BufferedReader(
new FileReader("E01_FileIntoList.java"));
String s;
while((s = in.readLine())!= null)
lines.add(s);
in.close();
ListIterator it =
lines.listIterator(lines.size());
while(it.hasPrevious())
System.out.println(it.previous());
}
}
展开阅读全文