Java程序设计复习题.docx

上传人:b****8 文档编号:9259230 上传时间:2023-02-03 格式:DOCX 页数:21 大小:48.78KB
下载 相关 举报
Java程序设计复习题.docx_第1页
第1页 / 共21页
Java程序设计复习题.docx_第2页
第2页 / 共21页
Java程序设计复习题.docx_第3页
第3页 / 共21页
Java程序设计复习题.docx_第4页
第4页 / 共21页
Java程序设计复习题.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

Java程序设计复习题.docx

《Java程序设计复习题.docx》由会员分享,可在线阅读,更多相关《Java程序设计复习题.docx(21页珍藏版)》请在冰豆网上搜索。

Java程序设计复习题.docx

Java程序设计复习题

Java程序设计复习题

一、单项选择题

1.下面哪些是java语言中的关键字?

A.sizeofB.abstractC.NULLD.Native

2.下面语句哪个是正确的?

A.char='abc';B.longl=oxfff;C.floatf=0.23;D.double=0.7E-3;

3.以下程序测试String类的各种构造方法,试选出其运行效果。

classSTR{

publicstaticvoidmain(Stringargs[]){

Strings1=newString();

Strings2=newString("String2");

charchars[]={'a','','s','t','r','i','n','g'};

Strings3=newString(chars);

Strings4=newString(chars,2,6);

bytebytes[]={0,1,2,3,4,5,6,7,8,9};

StringBuffersb=newStringBuffer(s3);

Strings5=newString(sb);

System.out.println("TheStringNo.1is"+s1);

System.out.println("TheStringNo.2is"+s2);

System.out.println("TheStringNo.3is"+s3);

System.out.println("TheStringNo.4is"+s4);

System.out.println("TheStringNo.5is"+s5);

}

}

A.TheStringNo.1is

TheStringNo.2isString2

TheStringNo.3isastring

TheStringNo.4isstring

TheStringNo.5isastring

B.TheStringNo.1is

TheStringNo.2isString2

TheStringNo.3isastring

TheStringNo.4istring

TheStringNo.5isastring

C.TheStringNo.1is

TheStringNo.2isString2

TheStringNo.3isastring

TheStringNo.4isstrin

TheStringNo.5isastring

D.以上都不对

4.下面语句段的输出结果是什么?

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.defaultB.default,zero

C.errordefaultclausenotdefinedD.nooutputdisplayed

5.有关类Demo,哪句描述是正确的?

publicclassDemoextendsBase{

privateintcount;

publicDemo(){

System.out.println("ADemoobjecthasbeencreated");

}

protectedvoidaddOne(){count++;}

}

A.当创建一个Demo类的实例对象时,count的值为0。

B.当创建一个Demo类的实例对象时,count的值是不确定的。

C.超类对象中可以包含改变count值的方法。

D.Demo的子类对象可以访问count。

6.当编译和运行下列程序段时,会发生什么?

classBase{}

classSubextendsBase{}

classSub2extendsBase{}

publicclassCEx{

publicstaticvoidmain(Stringargv[]){

Baseb=newBase();

Subs=(Sub)b;

}

}

A.通过编译和并正常运行。

B.编译时出现例外。

C.编译通过,运行时出现例外。

7.如果任何包中的子类都能访问超类中的成员,那么应使用哪个限定词?

A.publicB.privateC.protectedD.transient

8.下面的哪个选项是正确的?

classExSuper{

Stringname;

Stringnick_name;

publicExSuper(Strings,Stringt){

name=s;

nick_name=t;

}

publicStringtoString(){

returnname;

}

}

publicclassExampleextendsExSuper{

publicExample(Strings,Stringt){

super(s,t);

}

publicStringtoString(){

returnname+"a.k.a"+nick_name;

}

publicstaticvoidmain(Stringargs[]){

ExSupera=newExSuper("First","1st");

ExSuperb=newExample("Second","2nd");

System.out.println("ais"+a.toString());

System.out.println("bis"+b.toString());

}

}

A.编译时会出现例外。

B.运行结果为:

aisFirst

bissecond

C.运行结果为:

aisFirst

bisSeconga.k.a2nd

D.运行结果为:

aisFirsta.k.a1nd

bisSeconda.k.a2nd

9.运行下列程序的结果是哪个?

abstractclassMineBase{

abstractvoidamethod();

staticinti;

}

publicclassMineextendsMineBase

{

publicstaticvoidmain(Stringargv[]){

int[]ar=newint[5];

for(i=0;i

System.out.println(ar[i]);

}

}

A.打印5个0。

B.编译出错,数组ar[]必须初始化。

C.编译出错,Mine应声明为abstract。

D.出现IndexOutOfBoundes的例外。

10.请问所有的例外类皆继承哪一个类?

A.java.io.ExceptionB.java.lang.Throwable

C.java.lang.ExceptionD.java.lang.Error

11.下面程序段的执行结果是什么?

publicclassFoo{

publicstaticvoidmain(String[]args){

try{

return;}

finally{System.out.println("Finally");

}

}

}

A.程序正常运行,但不输出任何结果。

B.程序正常运行,并输出"Finally"。

C.编译能通过,但运行时会出现一个例外。

D.因为没有catch语句块,所以不能通过编译。

12.编译Java Application源程序文件产生的字节码文件的扩展名为(     )。

A.javaB.class

C.htmlD.exe

13.下列哪个是合法的Java标识符(     )?

A.&2B.123.9

C._2#D.public

14.设有下面两个类的定义:

class Person{long id;  //身份证号

String name;  //姓名}

classStudent extends Person{int score; //入学总分

int getScore(){return score;}}

问:

类Person和类Student的关系是(     )。

A.包含关系B.继承关系

C.关联关系D.无关系,上述类定义有语法错误

15.在使用interface声明一个接口时,只可以使用(     )修饰符修饰该接口。

A.privateB.protected

C.private protectedD.public

16.在编写异常处理的Java程序中,每个catch语句块都应该与(     )语句块对应,使得用该语句块来启动Java的异常处理机制。

A.if–elseB.switch

C.tryD.throw

17.请问所有的例外类皆继承哪一个类?

A.java.io.ExceptionB.java.lang.Throwable

C.java.lang.ExceptionD.java.lang.Error

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

A.GraphicsB.Graphics2D

C.StringD.Color

19.指出正确的表达式

A.byte=128;B.Boolean=null;

C.longl=0xfffL;D.double=0.9239d;

20.类的设计要求它的某个成员变量不能被外部类直接访问,应该使用下面的哪些修饰符获得需要的访问控制()?

A.publicB.default

C.protectedD.private

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

A.ArrayListmyList=newObject();

B.ListmyList=newArrayList();

C.ArrayListmyList=newList();

D.ListmyList=newList();

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

A.GraphicsB.Graphics2D

C.StringD.Color

23.指出正确的表达式

A.byte=128;B.Boolean=null;

C.longl=0xfffLD.double=0.9239d;

24.指出下列程序运行的结果

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.goodandabcB.goodandgbc

C.testokandabcD.testokandgbc

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

publicclassXextendsThreadimplementsRunable{

 publicvoidrun(){

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

 }

 publicstaticvoidmain(Stringargs[])

 {

  Threadt=newThread(newX());

  t.start();

 }

}

A.第一行会产生编译错误B.第六行会产生编译错误

C.第六行会产生运行错误D.程序会运行和启动

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

A.FileInputStreamin=newFileInputStream("file.dat");

in.skip(9);intc=in.read();

B.FileInputStreamin=newFileInputStream("file.dat");

in.skip(10);intc=in.read();

C.FileInputStreamin=newFileInputStream("file.dat");

intc=in.read();

D.RandomAccessFilein=newRandomAccessFile("file.dat");

in.skip(9);intc=in.readByte();

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

A.CardLayoutB.FlowLayout

C.BorderLayoutD.GridLayout

28.给出下面代码:

publicclassPerson{

  staticintarr[]=newint[10];

  publicstaticvoidmain(Stringa[])

  {

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

  }

}

哪个语句是正确的?

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

C.输出零;D.输出空。

29.哪个关键字可以对对象加互斥锁?

A.transientB.synchronized

C.serializeD.static

30.下列哪些语句关于内存回收的说明是正确的?

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

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

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

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

二、填空题

1.分析下面一段程序:

classAclass

{

   voidgo(){System.out.println("Aclass"); }

  }

publicclassBclassextendsAclass

{

   voidgo(){System.out.println("Bclass");}

  publicstaticvoidmain(Stringargs[])

{

   Aclassa=newAclass();

   Aclassa1=newBclass();

  a.go();

  a1.go();

  }

}

程序运行结果是:

2.指出下列程序的运行结果

  publicclassA1

{

publicstaticvoidmain(Stringargs[])

{

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");

}

}

}

程序运行结果是:

3.下面程序段的执行结果是什么?

publicclassFoo

{

publicstaticvoidmain(String[]args)

{

try{return;}

finally{System.out.println("Finally");}

}

}

程序运行结果是:

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");

System.out.print(ex.ch);

}

publicvoidchange(Stringstr,charch[])

{

str="testok";

ch[0]='g';

}

}

程序运行结果是:

5.下列代码哪几行会出错:

1)publicclassModify

2){

3)publicstaticvoidmain(Stringargs[])

4){

5)intI,j,k;

6)I=100;

7)while(I>0)

8){

9)j=I*2;

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

11)k=k+1;

12)I--;

13)}

14)}

15)}

6.请写出下面程序的运行结果。

publicclassTestextendsTT

{

publicstaticvoidmain(Stringargs[])

{

Testt=newTest("Tom");

}

publicTest(Strings)

{

super(s);

System.out.println("Howdoyoudo?

");

}

publicTest()

{

this("IamTom");

}

}

classTT

{

publicTT()

{

System.out.println("Whatapleasure!

");

}

publicTT(Strings)

{

this();

System.out.println("Iam"+s);

}

}

结果:

7.给定下面的未完成的代码片断:

publicclassExample

{

   intx,y;

  publicExample(inta)

{

x=a;

  }

  publicExample(inta,intb)

{

   //和上面一个参数的构造方法做同样的操作,包括赋值x=a

y=b;

  }

  }

  如果要用最简捷的一行代码实现"//和上面一个参数的…"注释所指出的功能,请写出你认为最合适的一行代码:

8.下列程序中构造了一个SET并且调用其方法add(),输出结果是_______

publicclassA{

publicinthashCode(){return1;}

publicBooleanequals(Objectb){returntrue}

publicstaticvoidmain(Stringargs[])

{Setset=newHashSet();

set.add(newA());

set.add(newA());

set.add(newA());

System.out.println(set.size());

}

}

9.下列程序的运行结果是_______

classA

{classDog

{privateStringname;

  privateintage;

  publicintstep;

  Dog(Strings,inta)

  { name=s;

   age=a;

   step=0;

   }

  publicvoidrun(Dogfast)

  {fast.step++; }

}

  publicstaticvoidmain(Stringargs[])

  {Aa=newA();

  Dogd=a.newDog("Tom",3);

  d.step=25;

  d.run(d);

  System.out.println(d.step);

  }

}

10.Java中类成员的限定词有以下几种:

private,public,,。

其中,的限定的范围最大。

11.Java中所有类都是类的子类。

12.请填出在java.lang包中与下列基本数据类型相对应的封装类:

float:

java.lang.Float,char:

,boolean:

13.给定下面的未完成的代码片断:

  publicclassExample{

intx,y;

  publicExample(inta){

 …

 x=a;

  }

  publicExample(inta,intb){

   //和上面一个参数的构造方法做同样的操作,包括赋值

x=ay=b;

}

  }

  如果要用最简捷的一行代码实现"//和上面一个参数的…"注释所指出的功能,请写出你认为最合适的一行代码:

14.如果有一个类MyFrame是Frame的子类,能够被不同包中的类所使用,同时又能够为线程提供运行代码(run()方法),请写出该类的声明头。

你的解答:

三.阅读程序回答问题

⒈下面是JavaAPI类库中System类的定义原型

publicfinalclassjava.lang.Systemextendsjava.lang.Object

{

publicstaticPrintS

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

当前位置:首页 > 解决方案 > 学习计划

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

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