在线留言 注册 登录
热门搜索:形考答案免费答案奥鹏答案

东大25春《JAVA语言程序设计ⅡX》在线平时作业2【标准答案】

Time2025-04-25Hits浏览量: 9
有奥鹏院校所有作业、毕业论文,详情请咨询请添加QQ : 103092222或微信: xyzlfx100

《JAVA语言程序设计Ⅰ》在线平时作业2-00001

试卷总分:100  得分:100

一、单选题 (共 20 道试题,共 60 分)

1.下列语句序列执行后,k 的值是( )。 int x=6, y=10, k=5; switch( x%y ) { case 0: k=x*y; case 6: k=x/y; case 12: k=x-y; default: k=x*y-x; }

A.60

B.54

C.0

D.5


2.如果你有下面的类定义 abstract class Shape{ abstract void draw(); } 请问,在试图编译下面的类定义时会发生什么情况? class Square extends Shape{ }

A.都可以成功编译

B.Shpe可以编译,而Square不能

C.Square可以编译,而Shape不能

D.Shape和Square都不能编译


3.下面的语句的作用是:( )。 Vector MyVector = new Vector(100,50);

A.创建一个数组类对象MyVector,有100个元素的空间,每个元素的初值为50。

B.创建一个向量类对象MyVector,有100个元素的空间,每个元素的初值为50。

C.创建一个数组类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。

D.创建一个向量类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。


4.下列代码中,将引起一个编译错误的行是 1)public class Test{ 2) int m,n; 3) public Test() {} 4) public Test(int a) {m=a;} 5) public static void main(String args[]){ 6) Test t1,t2; 7) int j,k; 8) j=0;k=0; 9) t1=new Test(); 10) t2=new Test(j,k); 11) } 12

A.第3行

B.第5行

C.第6行

D.第10行


5.Person, Student 和Teacher 都是类名。这些类有以下继承关系。 Person | -------------------- | | Student Teacher 并且在Java源代码中有如下表达式: Person p = new Student(); 如下哪个语句是正确的?

A.这条语句是合法的

B.这条语句是不合法的

C.编译时出错

D.编译正确但运行时出错


6.阅读下列代码后 public class Person{ int arr[]=new int[10]; public static void main(String args[]){ System.out.println(arr[1]); } } 正确的说法是

A.编译时将产生错误

B.编译时正确,运行时将产生错误

C.输出零

D.输出空


7.下面哪一个类可以访问foo包中的所有变量? package foo; class a{int c} class b{private int d} class c{public int e}

A.class a

B.class b

C.class c

D.都不能


8.若有循环: int x=5,y=20; do{ y-=x; x++; }while(++x<--y);则循环体将被执行( )。

A.0次

B.1次

C.2次

D.3次


9.下列语句序列执行后,k的值是( )。 int j=8, k=15; for( int i=2; i!=j; i++ ) { j-=2; k++; }

A.15

B.16

C.17

D.18


10.下列代码的执行结果是 public class Test { public int aMethod() { static int i=0; i++; System.out.println(i); } public static void main(String args[]) { Test test = new Test();

A.编译错误

B.0

C.1

D.运行成功,但不输出


11.设有下面的一个类定义: class AA { static void Show( ){ System.out.println("我喜欢Java!"); } } class BB { void Show( ){ System.out.println("我喜欢C++!"); } } 若已经使用AA类创建对象a和BB类创建对象b,则下面哪一个方法调用是正确的:( )

A.Show( ) b.Show( )

B.AA.Show( ) BB.Show( )

C.AA.Show( ) b.Show( )

D.Show( ) BB.Show( )


12.给定下面的类:   public class Example{   String str=new String(“good”);   char ch[]={'a','b','c'};   public static void main(String args[]){   Example ex=new Example();   ex.change(ex.str,ex.ch);   System.out.println(ex.str+”and”+ex.ch);   }   public void

A.good and abc

B.good and gbc

C.test ok and abc

D.test ok and gbc


13.下面程序的输出结果是什么? class Foo{ static void change(String s){ s=s.replace('j','l'); } public static void main(String args[]){ String s="java"; change(s); System.out.println(s); } }

A.lava

B.java

C.编译错误

D.运行时出现异常


14.下面的代码段中,执行之后i 和j 的值是什么? int i = 1; int j; j = i++;

A.1, 1

B.1, 2

C.2, 1

D.2, 2


15.下列程序段执行后t5的结果是( )。int t1 = 9, t2 = 11, t3=8;int t4,t5;t4 = t1 > t2 ? t1 : t2+ t1;t5 = t4 > t3 ? t4 : t3;

A.8

B.20

C.11

D.9


16.给出下列的代码,哪行在编译时可能会有错误? ① public void modify(){ ② int i, j, k; ③ i = 100; ④ while ( i > 0 ){ ⑤ j = i * 2; ⑥ System.out.println (" The value of j is " + j ); ⑦ k = k + 1; ⑧ } ⑨ }

A.4

B.6

C.7

D.8


17.给出下面的接口: interface A{ int method1(int i); int method2(int j); } 下面那个类实现了这个接口,并且不是抽象的?

A.class B implements A{ int method1(){} int method2(){} }

B.class B { int method1(int i){} int method2(int j){} }

C.class B implements A{ int method1(int i){} int method2(int j){} }

D.class B extends A{ int method1(int i){} int method2(int j){} }


18.下面的哪些程序段可以正确地获得从命令行传递的参数的个数?

A.int count = args.length;

B.int count = args.length-1;

C.int count=0; while(args[count]!=null) count++;

D.int count=0;while (!(args[count].equals(“”))) count++;


19.以下代码的输出结果是什么? class Foo{ public static void main(String args[]){ int x=4,j=0; switch(x){ case 1:j++; case 2:j++; case 3:j++; case 4:j++; case 5:j++; break; default:j++; } System.out.println(j); } }

A.1

B.2

C.3

D.编译错误


20.已知表达式int m[] = {0, 1, 2, 3, 4, 5, 6 }; 下面哪个表达式的值与数组下标量总数相等?

A.length()

B.length

C.length()+1

D.length+1


二、多选题 (共 10 道试题,共 40 分)

21.已知如下定义: String s = "story"; 下面哪些表达式是合法的?

A.s += "books";

B.char c = s[1];

C.int len = s.length;

D.String t = s.toLowerCase();


22.String s=”Example String”; 下面哪些语句是正确的?

A.s>>>=3;

B.int i=s.length();

C.s[3]=”x”;

D.String short_s=s.trim();

E.String t=”root”+s;


23.下面的哪些程序片断可能导致错误。

A.String s="Gonewiththewind"; String t="good"; String k=s+t;

B.String s="Gonewiththewind"; String t; t=s[3]+"one";

C.String s="Gonewiththewind"; String standard=s.toUpperCase();

D.String s="homedirectory"; String t=s-"directory".


24.假定文件名是“Fred.java”,下面哪个是正确的类声明。

A.public class Fred{   public int x = 0;   public Fred (int x){   this.x=x;   }   }

B.public class fred{   public int x = 0;   public Fred (int x){   this.x=x;   }   }

C.public class Fred extends MyBaseClass{   public int x = 0; }


25.在如下源代码文件Test.java中, 哪个是正确的类定义?

A.public class test { public int x = 0; public test(int x) { this.x = x; } }

B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }

C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }

D.public class


26.你怎样从下面main()的调用中访问单词“kiss”? java lyrics a kiss is but a kiss

A.args[0]

B.args[1]

C.args[2]

D.args[3]

E.args[4]

F.args[5]


27.如果有以下代码,哪几个数字能产生输出 "Test2" 的结果? Switch(x){ case 1: System.out.println("Test1"); case 2: case 3: System.out.println("Test2"); break;} System.out.println("Test3"); }

A.0

B.1

C.2

D.3


28.已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?

A.t.f

B.this.n

C.Test.m

D.Test.n


29.给出下面的代码段: public class Base{ int w, x, y ,z; public Base(int a,int b) { x=a; y=b; } public Base(int a, int b, int c, int d) { //赋值 x=a, y=b w=d; z=c; } } 在代码说明//赋值 x=a, y=b处写入如下哪几行代码是正确的?

A.Base(a,b)

B.x=a,y=b;

C.x=a;y=b;

D.this(a,b);


30.请选出创建数组的正确语句。

A.float f[][] = new float[6][6];

B.float []f[] = new float[6][6];

C.float f[][] = new float[][6];

D.float [][]f = new float[6][6];


吐血推荐

奥鹏,国开形考,广开,电大在线,各省平台,新疆一体化,各类成人教育等学习。详情请咨询QQ : 103092222或微信: xyzlfx100

添加微信查看答案

东大25春《JAVA语言程序设计ⅡX》在线平时作业2【标准答案】_学优资料分享网

添加微信二维码,了解更多学习技巧,平 台作业、毕业论文完成时间友情提醒。。

合作洽谈

诚信为本,合作共赢

欢迎各大学习中心前来治谈;有意请联系我们

推荐作业

留言板
captcha
感谢留言
我们会尽快与您联系
关闭