JAVA期末考试考卷及答案Word文档格式.docx

上传人:b****6 文档编号:20709837 上传时间:2023-01-25 格式:DOCX 页数:10 大小:43.05KB
下载 相关 举报
JAVA期末考试考卷及答案Word文档格式.docx_第1页
第1页 / 共10页
JAVA期末考试考卷及答案Word文档格式.docx_第2页
第2页 / 共10页
JAVA期末考试考卷及答案Word文档格式.docx_第3页
第3页 / 共10页
JAVA期末考试考卷及答案Word文档格式.docx_第4页
第4页 / 共10页
JAVA期末考试考卷及答案Word文档格式.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

JAVA期末考试考卷及答案Word文档格式.docx

《JAVA期末考试考卷及答案Word文档格式.docx》由会员分享,可在线阅读,更多相关《JAVA期末考试考卷及答案Word文档格式.docx(10页珍藏版)》请在冰豆网上搜索。

JAVA期末考试考卷及答案Word文档格式.docx

程序用户自定义的Applet子类中,

般需要重载父类的(D)

法来完成一些画图操作

C.init()

D.paint()

4、不允许作为类及类成员的访问控制符的是

 

前缀就可以调用它,该方法头的形式为(A

C.finalvoidmethod()D.abstractvoidmethod()

二、填空题(每空格1分,共20分)

1、幵发与运行Java程序需要经过的三个主要步骤为编辑源程序

编译生成字节码和解释运行字节码。

MyApplet必须是Applet类的子类并且存储该源程序文件的文件名为

MyApplet。

3、如果一个JavaApplet程序文件中定义有3个类,则使用Sun公司的JDK编译

器javac.exe编译该源程序文件将产生二个文件名与类名相同而

扩展名为.class的字节码文件。

4、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占

用2字节内存空间,这样,无论是中文字符还是英文字符,都是占

用_J2字节内存空间。

5、设x=2,则表达式(x++)/3的值是1。

6、若x=5,y=10,贝9x<

y和x>

=y的逻辑值分别为true和false。

7、抽象(abstract)方法方法是一种仅有方法头,没有具体方法体和操作实现的

方法,该方法必须在抽象类之中定义。

最终(final)方法方法是不能被当前类的子类

重新定义的方法。

8、创建一个名为MyPackage的包的语句是packageMyPackag,

该语句应该放在程序的位置为:

应该在程序第一句。

9、设有数组定义:

intMylntArray[]={10,20,30,40,50,60,70};

执行以下几个语句后的输出结果是120o

ints=0;

for(inti=0;

i<

MylntArray.length;

i++)

if(i%2==1)

s+=MylntArray[i];

10、在Java程序中,通过类的定义只能实现单.重继承,但通过接口的定义可以实

现多重继承关系。

三、写出下列程序完成的功能。

(每小题5分,共20分)

1、publicclassSum{publicstaticvoidmain(Stringargs[])

{doublesum=0.0;

for(inti=1;

=100;

sum+=1.0/(double)i;

}

}答:

计算1/1+1/2+1/3+...+1/100的值

2、importjava.io.*;

publicclassReverse

{publicstaticvoidmain(Stringargs[])

{inti,n=10;

inta[]=newint[10];

for(i=0;

n;

i++)

try{

BufferedReaderbr=newBufferedReader(

newInputStreamReader(System.in));

输入一个整数

然后逆序输出这10个整数

a[i]=Integer.parseInt(br.readLine());

//

}catch(IOExceptione){};

for(i=n—1;

i>

=0;

i)

}答:

从标准输入(键盘)读入10个整数存入整型数组a中,

3、importjava.awt.*;

publicclassabc

{publicstaticvoidmain(Stringargs[])

{newFrameOut();

}

classFrameOutextendsFrame//Frame

{Buttonbtn;

FrameOut()

{super("

按钮"

);

btn二newButton("

按下我"

setLayout(newFlowLayout());

add(btn);

setSize(300,200);

show();

创建一个标题为"

按钮"

的窗框,窗框中显示有

4、importjava.io.*;

{SubClasssb=newSubClass();

classSuperClass

{inta=10,b=20;

classSubClassextendsSuperClass

{intmax(){return((a>

b)a:

b);

}}答:

为系统定

义的窗框类

"

按下我"

字样的按钮

求两个数的最大值

四、写出下面程序的运行结果(每小题10分,共30分)

1、importjava.io.*;

{ABs=newAB("

Hello!

"

lloveJAVA."

classAB{

Strings1;

Strings2;

AB(Stringstr1,Stringstr2)

{s1=str1;

s2=str2;

publicStringtoString()

{returns1+s2;

1、Hello!

IloveJAVA.

2、importjava.io.*;

{

publicstaticvoidmain(Stringargs[])

{inti,s=0;

inta[]={10,20,30,40,50,60,70,80,90};

a」ength;

if(a[i]%3==0)s+=a[i];

s=180

五、使用Java语言编写程序。

(每小题10分,共20分)

1、编写一个字符界面的JavaApplication程序,接受用户输入的

10个整数的最大值和最小值。

答:

importjava.io.*;

{inti,n二10,max=0,min=0,temp=0;

max=min=Integer.parseInt(br.readLine());

for(i=2;

=n;

i++){

BufferedReaderbr=new

InputStreamReader(System.in));

temp=Integer.parseInt(br.readLine());

if(temp>

max)max二temp;

if(temp<

min)min=temp;

10个整数,并输出这

BufferedReader(new

2、编写一个完整的JavaApplet程序使用复数类Complex验证两个复数1+2i和3+4i相加产生一个新的复数4+6io

复数类Complex必须满足如下要求:

(1)复数类Complex的属性有:

RealPart:

int型,代表复数的实数部分

ImaginPart:

int型,代表复数的虚数部分

(2)复数类Complex的方法有:

Complex():

构造函数,将复数的实部和虚部都置0

Complex(intr,inti):

构造函数,形参r为实部的初值,i为虚部的初值。

ComplexcomplexAdd(Complexa):

将当前复数对象与形参复数对象相加,所得

的结果仍是一个复数值,返回给此方法的调用者。

StringToString():

把当前复数对象的实部、虚部组合成a+bi的字符串形式,

其中a和b分别为实部和虚部的数据。

答:

importjava.applet.*;

importjava.awt.*;

publicclassabcextendsApplet

Complexa,b,c;

publicvoidinit()

a=newComplex(1,2);

b=newComplex(3,4);

c=newComplex();

publicvoidpaingraphicsg)

c=plexAdd(b);

g.drawString("

第一个复数:

+a.toString(),10,50);

第二个复数:

+b.toString(),10,70);

两复数之和:

+c.toString(),10,90);

classComplex{

intRealPart;

//复数的实部

intImaginPart;

//复数的虚部

Complex。

{RealPart=0;

ImaginPart=0;

Complex(intr,inti)

{RealPart=r;

ImaginPart=i;

ComplexcomplexAdd(Complexa)

临时复数对象

Complextemp=newComplex();

temp.RealPart二RealPart+a.RealPart;

temp.ImaginPart=ImaginPart+a.ImaginPart;

returntemp;

{return(RealPart+"

+"

+ImaginPart+"

i"

Java线程程序题

classsumimplementsRunnable{

intsum=0;

inti;

publicvoidrun(){

for(i=i;

iv=ioo;

i++){

sum+=i;

classsumpro{

publicstaticvoidmain(Stringargs[]){

sumsum1=newsum();

Threadt=newThread(sum1);

t.start();

异常

1.importjava.io.*;

classA{

voidm()throwsRuntimeException{}

classBextendsA{

voidm()throwslOException{}

2.importjava.io.*;

voidm()throwsRuntimeException{}

voidm()throwsIOException{}

3.publicclasse8{

publicstaticvoidmain(Stringargs[]){

e8t=newe8();

t.first();

“Hi"

publicvoidfirst(){second();

publicvoidsecond()throwsException{

intx[]二newint[2];

x[3]=2;

4.publicclasse10{

publicstaticvoidmain(Stringargs[])throwsException{e10t=newe10();

publicvoidfirst()throwsException{second();

5使用super调用父类方法

classFishextendsAnimal{

publicFish(){super(O);

publicvoideat(){

publicvoidwalk(){

super.walk();

6.接口类的实现

classCatextendsAnimalimplementsPet{

Stringname;

publicCat(Stringn){

super(4);

name二n;

publicCat(){this("

publicStringgetName(){returnname;

publicvoidsetName(Stringn){name二n;

publicvoidplay(){

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

当前位置:首页 > 高等教育 > 工学

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

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