《Java程序设计》理论题库选择题单选题.docx

上传人:b****3 文档编号:26978660 上传时间:2023-06-24 格式:DOCX 页数:44 大小:32.09KB
下载 相关 举报
《Java程序设计》理论题库选择题单选题.docx_第1页
第1页 / 共44页
《Java程序设计》理论题库选择题单选题.docx_第2页
第2页 / 共44页
《Java程序设计》理论题库选择题单选题.docx_第3页
第3页 / 共44页
《Java程序设计》理论题库选择题单选题.docx_第4页
第4页 / 共44页
《Java程序设计》理论题库选择题单选题.docx_第5页
第5页 / 共44页
点击查看更多>>
下载资源
资源描述

《Java程序设计》理论题库选择题单选题.docx

《《Java程序设计》理论题库选择题单选题.docx》由会员分享,可在线阅读,更多相关《《Java程序设计》理论题库选择题单选题.docx(44页珍藏版)》请在冰豆网上搜索。

《Java程序设计》理论题库选择题单选题.docx

《Java程序设计》理论题库选择题单选题

《Java程序设计》理论题库—选择题(单选175题)

1.欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的()

A、ArrayListmyList=newObject();

B、ListmyList=newArrayList();

C、ArrayListmyList=newList();

D、ListmyList=newList();

2.paint()方法使用哪种类型的参数()

A、Graphics

B、Graphics2D

C、String

D、Color

3.指出正确的表达式()

A、byte=128;

B、Boolean=null;

C、longl=0xfffL;

D、double=0.9239d;

4.指出下列程序运行的结果()

publicclassExample{

Stringstr=newString("good");

char[]ch={'a','b','c'};

publicstaticvoidmain(Stringargs[]){

Exampleex=newExample();

ex.change(ex.str,ex.ch);

System.out.print(ex.str+"and");

Sytem.out.print(ex.ch);

}

publicvoidchange(Stringstr,charch[]){

str="testok";

ch[0]='g';

}

}

A、goodandabc

B、goodandgbc

C、testokandabc

D、testokandgbc

5.运行下列程序,会产生什么结果()

publicclassXextendsThreadimplementsRunable{

publicvoidrun(){

System.out.println("thisisrun()");

}

publicstaticvoidmain(Stringargs[])

publicvoidrun(){

System.out.println("thisisrun()");

}

publicstaticvoidmain(Stringargs[])

{

Threadt=newThread(newX());

t.start();

}

}

A、第一行会产生编译错误

B、第六行会产生编译错误

C、第六行会产生运行错误

D、程序会运行和启动

6.要从文件"file.dat"文件中读出第10个字节到变量C中,下列哪个方法适合()

A、FileInputStreamin=newFileInputStream("file.dat");in.skip(9);int

c=in.read();

B、FileInputStreamin=newFileInputStream("file.dat");in.skip(10);int

c=in.read();

C、FileInputStreamin=newFileInputStream("file.dat");intc=in.read();

D、RandomAccessFilein=newRandomAccessFile("file.dat");in.skip(9);int

c=in.readByte();

7.容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变()

A、CardLayout

B、FlowLayout

C、BorderLayout

D、GridLayout

8.给出下面代码:

publicclassPerson{

staticintarr[]=newint[10];

publicstaticvoidmain(Stringa[])

{

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

}

}

那个语句是正确的()

A、编译时将产生错误;

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

C、输出零;

D、输出空。

9.哪个关键字可以对对象加互斥锁()

A、transient

Bsynchronized

Cserialize

Dstatic

10.下列哪些语句关于内存回收的说明是正确的()

A、程序员必须创建一个线程来释放内存;

B、内存回收程序负责释放无用内存

C、内存回收程序允许程序员直接释放内存

D、内存回收程序可以在指定的时间释放内存对象

11.下列代码哪几行会出错()

1)publicvoidmodify(){

2)intI,j,k;

3)I=100;

4)while(I>0){

5)j=I*2;

6)System.out.println("Thevalueofjis"+j);

7)k=k+1;

8)I--;

9)}

10}}

A、line4

B、line6

C、line7

D、line8

12.MAX_LENGTH是int型public成员变量,变量值保持为常量100,用简短语句定义这个变量()

A、publicintMAX_LENGTH=100;

B、finalintMAX_LENGTH=100;

C、finalpublicintMAX_LENGTH=100;

D、publicfinalintMAX_LENGTH=100.

13.给出下面代码:

1)classParent{

2}privateStringname;

3}publicParent(){}

4}}

5)publicclassChildextendsParent{

6}privateStringdepartment;

7}publicChild(){}

8}publicStringgetValue(){returnname;}

9}publicstaticvoidmain(Stringarg[]){

10}Parentp=newParent();

11}}

12}}

那些行将引起错误()

A、第3行

B、第6行

C、第7行

D、第8行

14.类Teacher和Student是类Person的子类;

Personp;

Teachert;

Students;

//p,tandsareallnon-null.

if(tinstanceofPerson){s=(Student)t;}

最后一句语句的结果是()

A、将构造一个Student对象;

B、表达式是合法的;

C、表达式是错误的;

D、编译时正确,但运行时错误。

15.给出下面代码段:

1)publicclassTest{

2)intm,n;

3)publicTest(){}

4)publicTest(inta){m=a;}

5)publicstaticvoidmain(Stringarg[]){

6)Testt1,t2;

7)intj,k;

8)j=0;k=0;

9)t1=newTest();

10)t2=newTest(j,k);

11)}

12)}

哪行将引起一个编译时错误()

A、line3

B、line5

C、line6

D、line10

16.对于下列代码:

1)classPerson{

2)publicvoidprintValue(inti,intj){//...}

3)publicvoidprintValue(inti){//...}

4)}

5)publicclassTeacherextendsPerson{

6)publicvoidprintValue(){//...}

7)publicvoidprintValue(inti){//...}

8)publicstaticvoidmain(Stringargs[]){

9)Persont=newTeacher();

10)t.printValue(10);

11)}

第10行语句将调用哪行语句()

A、line2

B、line3

C、line6

D、line7

17.哪个关键字可以抛出异常()

A、transient

B、finally

C、throw

D、static

18.Main()方法的返回类型是()

A、int

B、void

C、boolean

D、static

19.System类在哪个包中()

A、java.util

B、java.io

C、java.awt

D、java.lang

20.对于下列代码:

publicclassParent{

publicintaddValue(inta,intb){

ints;

s=a+b;

returns;

}

}

classChildextendsParent{

}

下述哪些方法可以加入类Child?

()

A、intaddValue(inta,intb){//dosomething...}

B、publicvoidaddValue(inta,intb){//dosomething...}

C、publicintaddValue(inta){//dosomething...}

D、publicintaddValue(inta,intb)throwsMyException{//dosomething...}

21.给出下面代码:

publicclasstest{

staticinta[]=newa[10];

publicstaticvoidmain(Stringargs[]){

System.out.println(arr[10]);

}

}

那个选项是正确的()

A、编译时将产生错误;

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

C、输出零;

D、输出空。

22.下面哪些选项是正确的main方法说明()

A、publicmain(Stringargs[])

B、publicstaticvoidmain(Stringargs[])

C、privatestaticvoidmain(Stringargs[])

D、voidmain()

23.给定下面的代码片段:

1)Stringstr=null;

2)if((str!

=null)&&(str.length()>10)){

3)System.out.println("morethan10");

4)}

5)elseif((str!

=null)&(str.length()<5)){

6)System.out.println("lessthan5");

7)}

8)else{System.out.println("end");}

哪些行会导致错误()

A、line1

B、line2

C、line5

D、line8

24.下面哪种注释方法能够支持javadoc命令()

A、/**...**/

B、/*...*/

C、//

D、/**...*/

25.欲编写如下图的一个界面,用于显示用户指定的图像:

如果在区域A中只能放置一个

AWT组件,从各组件的本来功能角度考虑,最好使用哪种组件()

A、TextArea

B、Panel

C、Applet

D、Canvas

26.界面如上题所示。

若"Button1"的功能是:

点击后弹出一个用于输入的界面,获取用户

想要显示的图像文件名,则该界面最好是(从编程简单和程序不易出错的角度考虑)()

A、模式(Modal)Dialog

B、非模式(None-modal)Dialog

C、FileDialog

D、Frame

27.界面如上题所示。

如果在A区域使用某种AWT组件(java.awt.Component的子类)来

负责绘制图像,则绘图的语句最好应放在该组件的哪个方法中(考虑到应用程序和Java虚拟

机的AWT线程都会要求重画该组件)()

A、构造方法

B、paint(Graphicsg)

C、update(Graphicsg)

D、repaint()

28.下面关于Applet的说法正确的是()

A、Applet也需要main方法

B、Applet必须继承自java.awt.Applet

C、Applet能访问本地文件

D、Applet程序不需要编译

29.看下面一段程序:

classAclass{

voidgo(){

System.out.println("Aclass");

}

}

publicclassBclassextendsAclass{

voidgo{

System.out.println("Bclass");

}

publicstaticvoidmain(Stringargs[]){

Aclassa=newAclass();

Aclassa1=newBclass();

a.go();

a1.go();

}

以上程序运行结果是()

A、Aclass

Aclass

B、Bclass

Bclass

C、Aclass

Bclass

D、Bclass

Aclass

30.下列关于Java线程的说法那些是正确的()

A、每一个Java线程可以看成由代码、一个真实的CPU以及数据三部份组成。

B、创建线程的两种方法中,从Thread类中继承的创建方式可以防止出现多父类问题。

C、Thread类属于java.util程序包。

D、以上说法无一正确。

31.看以下程序:

booleana=false;

booleanb=true;

booleanc=(a&&b)&&(!

b);

intresult=c==false?

1:

2;

这段程序执行完后,c与result的值是()

A、c=false;result=1;

B、c=true;result=2;

C、c=true;result=1;

D、c=false;result=2;

32.运行下列程序,会产生什么结果()

publicclassXextendsThreadimplementsRunable{

publicvoidrun(){

System.out.println("thisisrun()");

}

publicstaticvoidmain(Stringargs[])

{

Threadt=newThread(newX());

t.start();

}

}

A、intheInnerouter

B、outer

C、intheInner

D、编译不通过

33.指出下列程序的运行结果()

inti=9;

switch(i){

default:

System.out.println("default");

case0:

System.out.println("zero");

break;

case1:

System.out.println("one");

case2:

System.out.println("two");

}

A、default

B、default,zero

C、errordefaultclausenotdefined

D、nooutputdisplayed那个

34.运行下列程序,会产生什么结果()

classOuter1{

privateinta;

voidfoo(doubled,finalfloatf){

Strings;

finalbooleanb;

classInner{

voidmethodInner(){

System.out.println("intheInner");

}

}

}

publicstaticvoidmain(Stringargs[])

{

Outer1me=newOuter1();

me.foo(123,123);

System.out.println("outer");

}

}

A、intheInnerouter

B、outer

C、intheInner

D、编译不通过

35.下面哪个单词是Java语言的关键字()

A、FloatB、thisC、stringD、unsigned

36.下面哪个是Java语言中正确的标识符()

A、3comB、importC、thatD、this

37.下面哪个语句不能定义一个字符变量()

A、charc1=06477;B、charc2=’\uface’;

C、charc4=0xbeef;D、charc3=\u0041;

38.下面哪个修饰符修饰的方法只能被本类中的其他方法使用()

A、protectedB、staticC、privateD、public

39.下面哪个运算后结果为32()

A、2^5B、(8>>2)<<4C、2>>5D、(2<<1)*(32>>3)

40.下面哪个是对字符串String的正确定义()

A、Strings1=null;B、Strings2=’null’;

C、Strings3=(String)‘abc’;D、Strings4=(String)‘\uface’;

41.下面哪条语句不能定义一个float型的变量()

A、floatf1=-343;B、floatf2=3.14;

C、floatf3=0x12345;D、floatf4=2.8F;

42.下面哪条语句定义了5个元素的数组()

A、int[]a={22,23,24,25,12};

B、inta[]=newint(5);

C、int[5]array;

D、int[]arr;

43.下面哪个范围是char型的取值范围()

A、-256~255B、-(2^15)~(2^15)-1

C、’\u0000’~‘\uffff’D、0~32767

44.给出一段程序,选择运行结果()

publicclasssss{

publicstaticvoidmain(Stringargs[])

{

Strings1=args[1];Strings2=args[2];

Strings3=args[3];Strings4=args[4];

System.out.println(“args[2]=”+s2);

}

}

命令行执行:

javasss1234结果是下面哪一个()

A、args[2]=2B、args[2]=nullC、args[2]=1D、运行出现异常

45.下面哪个描述是正确的()

A、Applet程序中不需要main()方法,也不能有

B、Application程序中可以没有main()方法。

C、Applet程序中可以不定义init()方法

D、Application程序中必须有run()方法

46.给出一段程序,试判断哪个是正确的结果()

publicclassrtExcept{

publicstaticvoidthrowit(){

System.out.print(“throwit”);

thrownewRuntimeException();}

publicstaticvoidmain(String[]aa){

try{

System.out.print(“hello“);

throwit();}

catch(Exceptionre){

System.out.print(“caught”);}

finally{

System.out.print(“finally”);}

System.out.print(“after”);

}

}

A、hellothrowitcaught

B、hellothrowitcaughtfinallyafter

C、hellothrowitRuntimeExceptionafter

D、hellothrowitcaughtfinallyafterRuntimeException

47.对一个java源文件aaa.java,编辑保存后但未编译,在其所在目录下执行javaaaa,

则接着会出现什么()

A、error:

cannotread:

aaa.java

B、无任何显示

C、Exceptioninthread"main"java.lang.NoClassDefFoundError:

aaa

D、程序正常执行并显示

48.编译java程序时出现error:

cannotread:

aaa.java,则下列原因最正确的是

()

A、原因是执行的当前目录下没有找到aaa.java文件。

B、原因是没有安装JDK开发环境。

C、原因是

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1