JAVA+2复习题库

{//do something...} 33、给出下面代码: (A)

public class test{

static int a[] = new a[10];

public static void main(String args[]) { System.out.println(arr[10]); } }

那个选项是正确的?

A、编译时将产生错误; B、编译时正确,运行时将产生错误;

C、输出零; D、输出空。 34、下面哪些选项是正确的main方法说明?(B)

A、public main(String args[]) B、public static void main(String args[])

C、private static void main(String args[]) D、void main()

Java语言程序设计 二、填空题:

(1)对象串行化可以很容易地扩展成支持Java对象的持续存储或持久存储,它提供了对象从流中重建的补充方式. (2)Vector类的对象是通过capacity和capacityIncrement

9

两个值来改变集合的容量,其中capacity表示集合最多能容纳的元素个数,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= in.readLine(); int year=Integer.parseInt(s);

if year % 4 = = 0 && year % 100! = 0 || year % 400 ==0)

{

System.out.println(\年是闰年.\

}

10

else {

System.out.println(\年不是闰年..\

} } }

(4) 下列程序的功能是:输入一个姓名,程序运行后,输出“姓名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

{

11

Label prompt;

TextField input,output; Button btnn; void FramInOut() {

prompt=new Label(\our name\

input=new TextField(10); output=new TextField(25); btnn=new Button(\ setLayout(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)

12

联系客服:779662525#qq.com(#替换为@)