《Java程序设计》练习题 联系客服

发布时间 : 星期一 文章《Java程序设计》练习题更新完毕开始阅读faa6b8d2a58da0116c174994

A) int addValue( int a, int b ){// do something...}

B) public void addValue (int a, int b ){// do something...} C) public int addValue( int a ){// do something...}

D) public int addValue( int a, int b ) {//do something...} 61、对于下列代码: 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(10); 11) }

第10行语句将调用哪行语句? ( ) A) line 2 B) line 3 C) line 6 D) line 7

62、编译和运行下面的应用程序,并在命令行界面输入12345,则回车后屏幕输出的结果是( )。

public class A {

public static void main(String args[]) throws IOException{ BufferedReader buf=new BufferedReader(

new InputStreamReader(System.in)); String str=buf.readLine();

int x=Integer.parseInt(str); System.out.println(x00); } }

A) 345 B)5 C) 123 D) 12345 63、以下程序段输出结果的是( )。 public class A implements B {

public static void main(String args[]) { int i;

A c1 = new A(); i= c1.k;

System.out.println(\ } }

interface B { int k = 10; }

A) i=0 B) i=10 C) 程序有编译错误 D) i=true 64、下面的程序段执行后输出的结果是( )

StringBuffer buf=new StringBuffer(\

buf.replace(0,7,”Hangzhou”)

System.out.println(buf.toString());

第 13 页 共 48 页

A) Hangzhou2008 B) Hangzhoug2008 C)Hangzhou008 D) Beijing2008 65、应用程序的main方法中有以下语句,则输出的结果是 ( )。

String s1=\

int b1=s1.compareTo (s2); System.out.println(b1);

A) false B)-32 C) 32 D) 0 66、下面的程序段的功能是( )。

File file1=new File(\ file1.mkdir();

A)在当前目录下生成子目录:\\xxx\\yyy B)生成目录: e:\\xxx\\yyy C)在当前目录下生成文件xxx.yyy D)以上说法都不对

67、网络资源定位器对应于Java的类java.net.URL,通过其成员方法( )获得端口。 A) getHost() B) getProtocol() C) getPort() D) getRef()

68、下面关于Java中线程的说法不正确的是( )?

A)调用join()方法可能抛出异常InterruptedException。 B)sleep()方法是Thread类的静态方法。

C)调用Thread类的sleep()方法可终止一个线程对象。 D)线程启动后执行的代码放在其run方法中。 69、给Java线程设定优先级的成员方法是( )。 A) getPriority() B) setPriority() C) getTread() D) setTread()

70、编写小应用程序(Applet)需要( )源程序文件和( )文本文件。 A) HTML、Java B) Java、HTML C) Applet、txt D) Java、txt

71、JTextArea实现了可以处理( )文本信息的文本框,但其不能自动进行( )处理。 a) 单行、滚屏 b) 多行、编辑 c) 多行、滚屏 d) 单行、编辑

72、常规菜单是由( )、( )和菜单项组成。 a) JMenuItem、JCheckBoxMenuItem b) JButton、JRadioButton c) JPopupMenu、JMenuItem d) JMenuBar、JMenu

73、GUI组件的左上角坐标是( ), 一个坐标系由X坐标和( )坐标构成。 a) (1,1)、Y b) (0,1)、X c) (0,0)、Y d) (1,0)、X

第 14 页 共 48 页

74、Color类定义了颜色( )和颜色( ),用于控制Java程序中的颜色。 a) 常量、内容 b) 常量、方法 c) 方法、对象 d) 方法、数据

75、Swing组件是( )组件。AWT组件由于捆绑在本地平台上,所以称为( )组件。 A)重量级、轻量级 B)高级、低级 C)低级、高级 D)轻量级、重量级

76、JFrame和JApplet不是( )的子类,因此它们没有( )方法。 A)JComponent、paintComponent B)JComponent、paint

C)JApplet、paintComponent D)JApplet、paint

77、程序员将可能发生异常的代码放在( )块中,后面紧跟着一个或多个( )块。 a) catch、try b) try、catch c) try、exception d) exception、try

78、RandomAccessFile类的( )方法可用于从指定流读取整数。 a) readLine b) readByte c) readInteger d) readInt

79、ServerSocket构造函数的第( )个参数指定了可以等待连接到服务器的最多客户机数目。

a) 1 b) 3 c) 4 d) 2

80、FlowLayout布局管理器按照组件加入容器的次序从( )到( )排列组件。 a) 上、下 b) 右、左 c) 左、右 d) 前、后

四、程序阅读题

1、阅读下面的程序:

① public class Test{

② public static void main(String[] a){ ③ int i = Integer.parseInt(a[0]); ④ switch (i) {

⑤ case 1:System.out.println(\⑥ case 2:System.out.println(\⑦ case 3:System.out.println(\⑧ case 4:System.out.println(\⑨ } ⑩ }

第 15 页 共 48 页

? }

上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,用java Test 2 运行得到的输出结果是什么?

2、阅读下面的程序:

1) public class Test{

2) public static void main(String[ ] args) { 3) int x,y=2,i=0,j=0;

4) if(args.length<2) System.exit(-1); 5) x = Integer.parseInt(args[1]); 6) switch(x){

7) case 2:switch(y){

8) case 1:i++;break; 9) case 2:j++;break; 10) default:i++;j++; 11) }

12) case 3:i++;j++;break; 13) default:i++;j++; 14) }

15) System.out.println(\16) System.out.println(\17) } 18) }

上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,用java Test 1 2 3 运行得到的运行结果是什么?

3、写出下列程序代码的运行结果: public class Test {

public static void main(String args[]) { int x = 10, y = 0; for(int i=2;i

switch(y) {

case 0: System.out.print(0);

case 1: System.out.print(1);break; case 2: System.out.print(2); case 3: System.out.print(3);break; default: System.out.print(4); } } }

4、写出下列程序代码的运行结果:

第 16 页 共 48 页