java复习题docWord文档下载推荐.docx

上传人:b****4 文档编号:8135207 上传时间:2023-05-10 格式:DOCX 页数:16 大小:27.50KB
下载 相关 举报
java复习题docWord文档下载推荐.docx_第1页
第1页 / 共16页
java复习题docWord文档下载推荐.docx_第2页
第2页 / 共16页
java复习题docWord文档下载推荐.docx_第3页
第3页 / 共16页
java复习题docWord文档下载推荐.docx_第4页
第4页 / 共16页
java复习题docWord文档下载推荐.docx_第5页
第5页 / 共16页
java复习题docWord文档下载推荐.docx_第6页
第6页 / 共16页
java复习题docWord文档下载推荐.docx_第7页
第7页 / 共16页
java复习题docWord文档下载推荐.docx_第8页
第8页 / 共16页
java复习题docWord文档下载推荐.docx_第9页
第9页 / 共16页
java复习题docWord文档下载推荐.docx_第10页
第10页 / 共16页
java复习题docWord文档下载推荐.docx_第11页
第11页 / 共16页
java复习题docWord文档下载推荐.docx_第12页
第12页 / 共16页
java复习题docWord文档下载推荐.docx_第13页
第13页 / 共16页
java复习题docWord文档下载推荐.docx_第14页
第14页 / 共16页
java复习题docWord文档下载推荐.docx_第15页
第15页 / 共16页
java复习题docWord文档下载推荐.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

java复习题docWord文档下载推荐.docx

《java复习题docWord文档下载推荐.docx》由会员分享,可在线阅读,更多相关《java复习题docWord文档下载推荐.docx(16页珍藏版)》请在冰点文库上搜索。

java复习题docWord文档下载推荐.docx

}

A.错误,因为变量i没有初始化B.nullC.1D.0

6.下列代码在编译运行过程中会产生的结果是(B)。

Strings=newString("

Bicycle"

);

intiBegin=1;

chariEnd=3;

System.out.println(s.substring(iBegin,iEnd));

A.BicB.icC.icyD.错误:

没有与substring(int,char)匹配的方法

7.下列代码在编译运行过程中会出现的结果是(D)。

publicclassQ{

doubleanar[]=newdouble[5];

System.out.println(anar[0]);

A.错误,anar初始化前被引用B.nullC.5D.0.0

8.下列代码在编译运行过程中会产生的结果是(C)。

abstractclassMineBase{

abstractvoidamethod();

publicclassMineextendsMineBase{

int[]ar=newint[5];

for(i=0;

i<

ar.length;

i++)

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

A.00000B.错误,因为ar初始化前被使用

C.错误,因为Mine没有声明为abstract,未覆盖MineBase中的amethod

D.下标越界

9.下列代码在编译运行后输出的结果是(D)。

inti=1;

switch(i){

case0:

System.out.println("

zero"

break;

case1:

one"

case2:

two"

default:

default"

A.oneB.one,twoC.defaultD.one,two,default

10.编译运行下列代码时得到的结果是(C)。

publicclassTuxextendsThread{

staticStringsName="

vandeleur"

Tuxt=newTux();

t.piggy(sName);

System.out.println(sName);

publicvoidpiggy(StringsName){

sName=sName+"

wiggy"

start();

publicvoidrun(){

for(inti=0;

4;

i++){

"

+i;

A.编译出错B."

vandeleurwiggy"

C."

vandelur"

D."

vandeleurwiggy0123"

11.编译运行下列代码时显示的结果是(C)。

importjava.awt.*;

publicclassButtextendsFrame{

ButtMyBut=newButt();

Butt(){

setLayout(newBorderLayout());

ButtonHelloBut=newButton("

Hello"

ButtonByeBut=newButton("

Bye"

add(HelloBut,BorderLayout.NORTH);

add(ByeBut,BorderLayout.SOUTH);

setSize(300,300);

setVisible(true);

A.两按钮占据整个框架,左边为Hello,右边为ByeB.Bye按钮占据整个框架

C.两按钮位于框架上下方,上边为Hello,下边为ByeD.Hello按钮占据整个框架

12.下列代码在编译运行过程中会产生的结果是(C)。

Integerten=newInteger(10);

Longnine=newLong(9);

System.out.println(ten+nine);

System.out.println(i+ten);

A.19B.10C.19D.错误:

不能转换整型数

201111

13.下列代码在编译运行过程中会出现的结果是(D)。

intanar[]=newint[]{1,2,3};

System.out.println(anar[2]);

A.1B.错误,因为anar初始化前被引用C.错误,因为数组大小必须确定D.3

14.在含有"

Java"

的字符串s中找到字母v的位置(即2),应该使用的语句是(C)。

A.mid(2,s);

B.charAt

(2);

C.s.indexOf('

v'

D.indexOf(s,'

15.假定有如下声明

Strings1=newString("

Strings2=newString("

there"

Strings3=newString();

则下列语句中,合法的是(A)。

A.s3=s1+s2;

B.s3=s1-s2;

C.s3=s1&

s2;

D.s3=s1&

&

s2

16.下列代码在编译运行过程中会产生的结果是(C)。

A.编译通过,run方法会输出i的增值B.编译时代码出错

C.编译通过,调用start会输出i的增值D.编译器出错,因while没有得到真(true)参数

classBackgroundimplementsRunnable{

inti=0;

while(true){

i++;

i="

+i);

}//Endwhile

}//Endrun

}//Endclass

17.给定如下代码设置frame颜色为粉色(pink)的是(D)。

publicclassSetFextendsFrame{

SetFs=newSetF();

s.setSize(300,200);

s.setVisible(true);

A.s.color=Color.pinkB.s.setColor(PINK);

C.s.Background(pink);

D.s.setBackground(Color.pink);

18.试图编译运行如下代码时会出现(A)。

publicclassConv{

Convc=newConv();

ello"

c.amethod(s);

publicvoidamethod(Strings){

Stringc="

H"

c=c+s;

System.out.println(c);

A.编译通过,并输出"

B.编译通过,并输出"

C.编译通过,并输出elloHD.编译时错

19.给定如下代码,能让Baseconstructor输出字符串"

baseconstructor"

的是(D)。

classBase{

Base(inti){

Base(){

publicclassSupextendsBase{

Sups=newSup();

//One

Sup()

{

//Two

publicvoidderived()

//Three

A.在//One处放置Base(10);

B.在//One处放置super(10);

C.在//Three处放置super(10);

D.在//Two处放置super(10);

20.给定如下代码,其输出是(C)。

publicclassPass{

staticintj=20;

inti=10;

Passp=newPass();

p.amethod(i);

System.out.println(j);

publicvoidamethod(intx){

x=x*2;

j=j*2;

A.10,and20B.20and40C.10and40D.错误,因为amethod参数与变量不匹配

21.在同一目录下存放有这些文件,如果Base.java文件没有编译,则试图编译和运行Class1.java时出产生(D)。

//Base.java

packageBase;

protectedvoidamethod(){

amethod"

}//Endofamethod

}//Endofclassbase

packageClass1;

//Class1.java

publicclassClass1extendsBase{

Baseb=newBase();

b.amethod();

}//Endofmain

}//EndofClass1

A.编译错:

MethodsinBasenotfound

B.编译错:

Unabletoaccessprotectedmethodinbaseclass

C.编译通过并输出"

D.编译错:

SuperclassClass1.BaseofclassClass1.Class1notfound

22.试图编译运行如下代码时会产生的结果是(A)。

privateclassBase{

inti=100;

publicclassPriextendsBase{

staticinti=200;

Prip=newPri();

}

A.编译时有错,class不允许使用修饰符privateB.200C.100200D.100

23.试图编译运行如下代码产生的结果是(A)。

publicclassRef{

Refr=newRef();

r.amethod(r);

publicvoidamethod(Refr){

inti=99;

multi(r);

publicvoidmulti(Refr){

r.i=r.i*2;

A.编译时出错B.99C.198D.运行时错

24.若将变量i的值赋给数组ia[]的元素,则在//Forloop注释行后应放的代码是(B)。

publicclassLin{

Linl=newLin();

l.amethod();

publicvoidamethod(){

intia[]=newint[4];

//StartForloop

ia[i]=i;

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

A.for(inti=0;

i<

ia.length()-1;

i++)B.for(inti=0;

i<

ia.length();

C.for(inti=1;

4;

i++)D.for(inti=0;

ia.length;

i++)

25.编译运行如下代码时会出现(D)。

privatevoidamethod(intiBase){

Base.amethod"

classOverextendsBase{

Overo=newOver();

intiBase=0;

o.amethod(iBase);

publicvoidamethod(intiOver){

Over.amethod"

A.编译时错,提示Base.amethodisprivateB.输出"

C.运行时错,提示Base.amethodisprivateD.输出"

二、编程题(本题共4题,第一题10分,第二题15分,第三题10分,第四题15分,总分50分)

1、(矩形类Rectangle)设计一个名为Rectangle的类表示矩形。

这个类包括:

●两个名为width和height的double型数据域,它们分别表示矩形的宽和高。

width和height的默认值都是1。

●创建默认矩形的无参构造方法。

●一个创建width和height为指定值的矩形的构造方法。

●一个名为getArea()的方法返回矩形的面积。

●一个名为getPerimiter()的方法返回周长。

画出该类的UML图。

实现这个类。

编写一个测试程序,创建两个Rectangle对象----一个矩形宽为4而高为40,另一个矩形宽为3.5而高为35.9。

依照每个矩形的宽、高、面积和周长的顺序显示。

publicclassExercise8_1{

publicstaticvoidmain(String[]args){

RectanglemyRectangle=newRectangle(4,40);

System.out.println("

Theareaofarectanglewithwidth"

+myRectangle.width+"

andheight"

+

myRectangle.height+"

is"

+myRectangle.getArea());

Theperimeterofarectangleis"

+myRectangle.getPerimeter());

RectangleyourRectangle=newRectangle(3.5,35.9);

yourRectangle.width+"

yourRectangle.height+"

yourRectangle.getArea());

yourRectangle.getPerimeter());

}

classRectangle{

//Datamembers

doublewidth=1,height=1;

//Constructor

publicRectangle(){

publicRectangle(doublenewWidth,doublenewHeight){

width=newWidth;

height=newHeight;

publicdoublegetArea(){

returnwidth*height;

publicdoublegetPerimeter(){

return2*(width+height);

2、(写/读数据)编写一个程序,如果名为Exercise9_19.txt的文件不存在,则创建该文件。

使用文本I/O编写随机产生100个整数给文件。

文件中的数据由空格分开。

从文件中读回数据然后显示排好序的数据。

提示:

在main方法头抛出异常。

publicstaticvoidmain(String[]args)throwsException{}

importjava.util.*;

importjava.io.*;

publicclassExercise9_19{

publicstaticvoidmain(String[]args)throwsException{

//Checkifsourcefileexists

Filefile=newFile("

Exercise9_19.txt"

if(!

file.exists()){

//Createthefile

PrintWriteroutput=newPrintWriter(file);

for(inti=1;

=100;

i++){

output.print((int)(Math.random()*100)+"

output.close();

Scannerinput=newScanner(file);

int[]numbers=newint[100];

for(inti=0;

100;

numbers[i]=input.nextInt();

Arrays.sort(numbers);

System.out.print(numbers[i]+"

3、设计一个名为GeometricObject的类,该类包括:

●三个数据域:

Stringcolor,默认值为”white”;

booleanfilled;

java.util.DatedateCreated;

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

当前位置:首页 > PPT模板 > 图表模板

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2