JAVA复习题三卷合一版(陈玲修改)1(4)

2019-08-26 17:32

B class MyClass extends Object C public class MyClass

D public class MyClass extends Object 三、 程序解析题(10道)

1. ★在编译和运行下列代码时,什么情况可能会发生? public class Person{

static int arr[] = new int[10]; public static void main(String a[]) {

System.out.println(arr[1]); } }

A 编译时将产生错误;

B 编译时正确,运行时将产生错误; C 输出零; D 输出空。

2. 下列代码哪几行会出错: 1) public void modify() { 2) int I, j, k; 3) I = 100;

4) while ( I > 0 ) { 5) j = I * 2;

6) System.out.println (\7) k = k + 1; 8) I--; 9) } 10) } A line 4 B line 6 C line 7 D line 8

3.★ 运行下列程序, 会产生什么结果

public class X extends Thread implements Runable{

public void run(){

System.out.println(\}

public static void main(String args[]){

Thread t=new Thread(new X()); t.start();

16

} }

A 第一行会产生编译错误 B 第六行会产生编译错误 C 第六行会产生运行错误 D 程序会运行和启动 4. 指出下列程序运行的结果 public class Example{

String str=new String(\char[]ch={'a','b','c'};

public static void main(String args[]){

Example ex=new Example(); ex.change(ex.str,ex.ch);

System.out.print(ex.str+\Sytem.out.print(ex.ch); }

public void change(String str,char ch[]){

str=\ch[0]='g'; } }

A good and abc B good and gbc C test ok and abc D test ok and gbc

5. 编译下面代码段,会出现什么结果 Integer ten=new Integer(10); Long nine=new Long (9); System.out.println(ten + nine); int i=1;

System.out.println(i + ten); A 先输出19后输出20 B 先输出19后输出11 C Error: 不能转换类型 D 先输出10后输出1

6.★ 运行下面程序,会得到什么结果

String s=new String(\int iBegin=1;

17

char iEnd=3;

System.out.println(s.substring(iBegin,iEnd)); A Bic B ic C icy

D error: 没有匹配的方法substring(int,char) 7. 下面语句操作的结果是 System.out.println(4/3); A 6 B 0 C 1 D 7

8. 编译如下代码可能出现的结果是 public class Holt extends Thread{

private String sThreadName;

public static void main(String argv[]){

Holt h = new Holt(); h.go(); } Holt(){} Holt(String s){

sThreadName = s; }

public String getThreadName(){

return sThreadName; }

public void go(){

Holt first = new Holt(\first.start();

Holt second = new Holt(\second.start(); }

public void start(){

for(int i = 0; i < 2; i ++){

System.out.println(getThreadName() +i); try{

Thread.sleep(100); }catch(InterruptedExceptione){

18

System.out.println(e.getMessage()); } } } }

A 编译时出错

B 输出 first0, second0, first0, second1 C 输出 first0, first1, second0, second1 D 运行时出错

9. 当你试图编译运行如下代码时会出现什么结果 class Background implements Runnable{

int i=0;

public int run(){

while(true){

i++;

System.out.println(\} //End while return 1; }//End run }//End class

A 编译通过执行run方法会输出i递增值 B 编译通过当调用开始输出i递增值 C 在编译时代码引起错误. D 由于没有正确的参数编译时出错. 10. 编译下面代码会出现什么结果 public class Conv{

public static void main(String argv[]){

Conv c=new Conv();

String s=new String(\c.amethod(s); }

public void amethod(String s){

char c='H'; c+=s;

System.out.println(c); } }

A 编译通过并输出字符串\

19

B 编译通过并输出字符串\C 编译通过并输出字符串\D 编译出错

四、 程序填空题(10道) 1. 下列程序段执行的结果是: import java.io.* ; public class abc {

public static void main(String args[ ]) { int i , s = 0 ;

int a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 }; for ( i = 0 ; i < a.length ; i ++ ) if ( a[i]%3 = = 0 ) s += a[i] ; System.out.println(\} }

答案:s=180

2. 执行下列程序段的结果是:_________________ public class Example{

public static void main(String argc[]){

int x,a=2,b=3,c=4; x=++a+b+++c++;

System.out.println(\System.out.println(“a=”+a); System.out.println(“b=”+b); System.out.println(“c=”+c);

} }

答案是: x=10 a=3 b=4 c=5

20


JAVA复习题三卷合一版(陈玲修改)1(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2019年全国各地高考模拟作文题汇总分析

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: