JAVA基础知识测试题2_第1页
JAVA基础知识测试题2_第2页
JAVA基础知识测试题2_第3页
JAVA基础知识测试题2_第4页
JAVA基础知识测试题2_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、给定下列代码:

01.publicclassMud{

02.〃插入代码位置

03.System.out.printlnC^hi*);

04.)

05.}

下述有5个片段代码:

publicstaticvoidmain(,tring…,){(Stringa,Stringb,Strhingc,...)

publicstaticvoidmain(String.*a){

publicstaticvoidmain(String...a){

publicstaticvoidmain(String|...a){

publicstaticvoidmain(String…口a){

将上述代码插入第二行时,有几个可以编译通过?

A.0

B.1

C.2

D.3

E.4

F.5

2、已知下述代码

publicclassTcstStringl{

publicstaticvoidmain(String[]args){

Stringstr="420";

str+=42;

System,out.print(str);

)

)

请问输出了什么?

A.42

B.420

C.462

E.编译错误

F.可以编译通过,但是会出现运行(runtime)错误

3、publicvoidgo(){

Stringo=

z:

for(intx=0;x<3;x++){

fordnty=0;y<2;y++){

x=0y=0o="00”

x=0y=lo=M0001

x=l不执行,x=2y=0()0012C

if(x==l)break;

if(x==2&&y==l)breakz;

o=o+x+y;002

}

System,out.prinlln(o);

)

当调用上述代码段中的go()方法时会发生什么?

A.00

B.0001

D.00012021

E.编译错误

E.可以编译通过,但是会出现运行(runtime)错误

4、给定下述代码:

intx=0:

inty=10;

do{

y—;

++x;

}while(x<5):

System,out.print(x+"+y);

输出了什么?

A5,6

C.6,5

D.6,6

5、请问下述代码是如何输出的?(请把输出写在题下空白处)

publicclassFoo{

//instancevariableinitializer

Strings="abc";

//constructor

publicFoo()*

System,out.printIn(^constructorcalled"):

)

//staticinitializer

static,

System,out.println(*staticinitializercalled“;;

//instanceinitializer

classinnere{

System.out.printInC/instanceinitializercalled");

)|

publicstaticvoidmain(String[]args){

System.out.println("Thisismaincalling!”);

newFoo();

newFoo();

)

)

输出结果:

staticinitializercalled

Thisismaincalling!

instanceinitializercalled

constructorcalled

instanceinitializercalled

constructorcalled

6、下面哪种类型可以填写在空白处?

pi=3.14f;

A.byte

B.float

C.double

D.short

7、给定下述代码

publicclassYippee{

publicstaticvoidmain(String[]args){

for(intx=1;x<args,length;x++){

System,out.print(args[x]+";

)

)

)

分别执行卜.而两行,

javaYippee

javaYippee1234

请问输出了什么?

A.没有输出

123

B.没有输出

234

C.没有输出

1234

I).可以编译通过,但是会出现运行(runtime)错误

123

E.可以编译通过,但是会出现运行(runtime)错误

234

F.可以编译通过,但是会出现运行(runtime)错误

1234

8、给定下列代码:

35.String与name="JaneCoe”;

36.int$agc=24;

37.Doubleheight=123.5;

38.double~temp=37.5;

下述中哪两个陈述是正确的?(选两个)

A.35行不会被编译

B.36行不会被编译

C.37行不会被编译

D.38行不会被编译

9、给定下列代码:

publicstaticvoidtest(Stringstr){

intcheck=4;

if(check=str.lengthO){

System,out.print(str.charAt(check-=1)+”,");

}else(

System,out.print(str.charAt(0)+”,");

}

}

执行卜述调用:

test("four");

test("tee");

lest("to");

结果是什么?

A.r,t,t,

B.r,e,o,

C.编译错误

I).可以编译通过,但是会出现运行(runtime)错误

10、给定下列代码:

publicclassPass2{

publicvoidmain(String[]args){

intx=6;

Pass2p=newPass2();

p.doStuff(x);

System.out.print(*mainx=*+x);

}

voiddoStuff(intx){

System.out.print(*doStuffx="+x++);

}

}

执行卜.述命令:

javacPass2.java

javaPass25

请问输出结果是什么?

A.编译错误

B.可以编译通过,但是会出现运行(runtime)错误

C.doStuffx=6mainx=6

D.doStuffx=6mainx=7

E.doStuffx=7mainx=6

F.doStuffx=7mainx=7

11、给定下述代码:

publicstaticvoidmain(String[]args){

for(inti=0;i<=10;i++){

if(i>6)break;

}

System.out.println(i);

}

输出了什么?

A.6

B.7

C.10

D.H

E.编译错误

F.可以编译通过,但是会出现运行(runlime)错误

12、给定下述代码:

1.publicclassMule{

2.publicstaticvoidmain(String[]args){

3.booleanassert=true:

4.if(assert){

5.System.out.printin(z,assertistrue");

6.)

7.)

8.}

Whichcommand-1ineinvocationswi11compile?

下列哪•行命令可以使上段代码编译成功

A.javacMule,java

B.javac-source1.3Mule,java

C.javac-source1.4Mule.java

D.javac-source1.5Mule,java

13、给定下述代码

1.publicclassVenus{

2.publicstaticvoidmain(String[]args){

3.int[]x={1,2,3);

4.inty[]={4,5,6};

5.newVenus().go(x,y);

6.)

7.

8.voidgo(int[]...z){

9.for(int[]a:z)

10.System,out.print(a[0]);

11.)

12.)

输出了什么?

A.1

B.12

C.14

D.123

E.编译错误

F.可以编译通过,但是会出现运行(runtime)错误

14、给定下述代码:

1.publicclassBreaker2{

2.staticStringo=

3.

4.publicstaticvoidmain(String[]args){

5.z:for(intx=2;x<7;x++){

6.if(x==3)

7.continue;

8.if(x==5)

9.breakz;

10.。=。+x:

11.)

12.System,out.println(o);

13.)

14.)

输出了什么?

A.2

B.24

C.234

D.246

E.2346

F.编译错误

15、编译并执行下述代码的结果是什么?

packageforecast;

publicclassWeather{

privatestaticbooleanheatWave=true;

publicstaticvoidmainO{

booleanheatWave=false;

System.out.print(heatWave);

}

)

A.true

B.false

C.无法编译

D.可以编译通过,但是返I可运行错误。

16、下列哪一个不是合法的类声明?

A.classbuiIding{}

B.classCostS{}

C.class5MainSt{}

D.class_0utside{}

17、填写下列代码中的空白处,使之可以编译并运行。

packageanimal:

publicclassCat{

publicStringname;

publicstaticvoidmain(String1]meow){

Catcat=nowCat();

_="Sadie”;

}

}

A.cat.name

B.cat-name

C.cat.setNamc

D.cat[name]

18.下述代码输出了什么?

packagebeach;

publicclassSand{

publicSand(){

System.out.print("a");

}

System,out.print("b");

publicvoidrun(){

newSand();

Sand();

)

pub!icstaticvoidmain(String...args){

newSand0.run();

}

}

A.a

B.ab

C.aab

D.上面的都不是

19、下述代码输出了什么?

publicclassTest{

staticintcount=0;

inti=0;

publicvoidchangecount(){

while(i<5){

i++;

count++;

}

}

publicst

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论