试题 百分网手机站

9月计算机二级Java预测题及答案

时间:2020-08-26 14:50:08 试题 我要投稿

2015年9月计算机二级Java预测题及答案

  一、选择题

  (1)Java语言具有许多优点和特点,下列选项中,哪个反映了Java程序并行机制的特点?

  A)安全性

  B)多线性

  C)跨平台

  D)可移植

  (2)下列哪个类声明是正确的?

  A)abstract final class HI{···} B)abstract private move(){···}

  C)protected private number; D)public abstract class Car{···}

  (3)下列关于for循环和while循环的说法中哪个是正确的?

  A)while循环能实现的操作,for循环也都能实现

  B)while循环判断条件一般是程序结果,for循环判断条件一般是非程序结果

  C)两种循环任何时候都可替换

  D)两种循环结构中都必须有循环体,循环体不能为空

  (4)异常包含下列那些内容?

  A)程序中的语法错误

  B)程序的编译错误

  C)程序执行过程中遇到的事先没有预料到的情况

  D)程序事先定义好的可能出现的意外情况

  (5)Character流与Byte流的区别是

  A)每次读入的字节数不同

  B)前者带有缓冲,后者没有

  C)前者是块读写,后者是字节读写

  D)二者没有区别,可以互换使用

  (6)*事件和处理事件

  A)都由Listener完成

  B)都由相应事件Listener处登记过的构件完成

  C)由Listener和构件分别完成

  D)由Listener和窗口分别完成

  (7)Applet可以做下列那些操作?

  A)读取客户端文件B)在客户端主机上创建新文件

  C)在客户端装载程序库

  D)读取客户端部分系统变量

  (8)下列哪个属于容器的.构件?

  A)JFrame

  B)JButton

  C)JPnel D)JApplet

  (9)如果希望所有的控件在界面上均匀排列,应使用下列那种布局管理器?

  A)BoxLayout

  B)GridLayout

  C)BorderLayout

  D)FlowLouLayout

  (10)为实现多线程之间的通信,需要使用下列那种流才合适?

  A)Filter stream

  B)File stream

  C)Random access stream

  D)Pipde

  stream

  二、填空题

  (1)对象串行化可以很容易地扩展成支持Java对象的 [1],它提供了对象从流中重建的补充方式.

  (2)Vector类的对象是通过capacity和capacityIncrement两个值来改变集合的容量,其中capacity表示集合最多能容纳的

  [2] ,capacityIncrement表示每次增加多少容量,不是一个一个增加.

  (3)下列程序的功能是判断某一年是否为闰年.请在横线处填入适当内容,使程序能够正确运行.

  import java.io.*;

  public class LeapYear{

  public static void main(String arge[])throws IOException{

  InputStreamReader ir;

  BufferdeReadwe in;

  ir=new InputStreamReader(System.in);

  in=new BufferedReader(ir);

  System.out.println(“输入年份是:”);

  String s= [3] ;

  int year=Integer.parseInt(s);

  if year % 4 = = 0 && year % 100! = 0 // year % 400 = =

  0)

  {

  System.out.println(""+year+"年是闰年.");

  }

  else

  {

  System.out.println(""+year+"年不是闰年..");

  }

  }

  }

  (4)下面程序对数组中每个元素赋值,然后按逆序输出.请在横线处填入适当内容,使程序能正常运行.

  import java.io.*;

  public class ArrayTest{

  public static void main(String args[]){

  int i;

  int a[] = new int[5];

  for(i=0;i

  a[i]=i;

  for( [4] ;i>=0;i- -)

  System.out.println("a["+i+"]="a[i]);

  }

  }

  (5) 下列程序的功能是:输入一个姓名,程序运行后,输出“姓名Welcome you!”.例如,输入“张三Welcome

  you !”.请在下面横线处填入正确的方法名,使程序可以正确运行.

  import java,awt,*;

  import java.awt.event.*;

  public class welcomenYou{

  public static void main(String args[])

  {

  new FrameInOut();

  }

  }

  class FrameInOut extends Frame implements ActionListener

  {

  Label prompt;

  TextField input,output;

  Button btnn;

  void FramInOut()

  {

  prompt=new Label("Please input your name");

  input=new TextField(10);

  output=new TextField(25);

  btnn=new Button("Class");

  [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()+"Welcome you!");

  else

  {

  dispose();

  system.exit(0);

  }

  }

  }