完整word版java期末考试样卷及说明 要看啊Word下载.docx
《完整word版java期末考试样卷及说明 要看啊Word下载.docx》由会员分享,可在线阅读,更多相关《完整word版java期末考试样卷及说明 要看啊Word下载.docx(19页珍藏版)》请在冰点文库上搜索。
![完整word版java期末考试样卷及说明 要看啊Word下载.docx](https://file1.bingdoc.com/fileroot1/2023-5/8/9c463c22-64f2-4440-a410-07154ecaa335/9c463c22-64f2-4440-a410-07154ecaa3351.gif)
C程序运行时的错误 D程序编译和运行时发生的错误
11.类Panel默认的布局管理器是(B)。
A、BorderLayoutB、FlowLayout
C、GridLayoutD、CardLayout
12.下面哪个方法与applet的显示无关?
(B)
A、update()B、draw()
C、repaint()D、paint()
13.已知如下代码:
publicclassTest{
publicstaticvoidmain(Stringarg[])
{
longa[]=newlong[10];
System.out.println(a[6]);
}
请问哪个语句是正确的?
(B)
A程序输出nullB程序输出0
C因为long[]数组声明不正确,程序不能被编译
D程序被编译,但在运行时将抛出一个ArrayIndexOutOfBoundsException异常
14.Java语言不是(C)
A、高级语言B、编译型语言
C、结构化设计语言D、面向对象设计语言
15.关于以下程序段的说明正确的是(C)
publicclassArrayTest{
publicstaticvoidmain(Stringargs[]){
try{
intx[]=newint[-5];
System.out.println("
此行将无法被执行!
"
);
}catch(NegativeArraySizeExceptione){
exception:
数组下标不能为负数。
}
}
A、编译通过,输出:
此行将无法被执行!
B、编译通过,输出:
exception:
C、编译通过,输出:
D、编译不能通过
16.Java源文件和编译后的文件扩展名分别为(B)。
A、.class和.javaB、.java和.class
C、.class和.classD、.java和.java
17.以下有关构造函数的说法,正确的是:
(A)。
A、一个类的构造函数可以有多个
B、构造函数在类定义时被调用
C、构造函数只能由对象中的其它方法调用
D、构造函数可以和类同名,也可以和类名不同
18.为类Employee中的一个无形式参数且无返回值的方法method书写方法头,以便使用类名Employee作为前缀就可以调用它(即可以通过类名调用方法method),该方法头的形式为(
A
)。
A、static
void
method()
B、public
C、final
D、abstract
method()
19.下列代码的执行结果是:
(
C
publicclassTest5{
publicstaticvoidmain(Stringargs[]){
Strings1=newString("
hello"
Strings2=newString("
System.out.print(s1==s2);
System.out.print("
"
System.out.println(s1.equals(s2));
A、true,falseB、true,true
C、false,trueD、false,false.
20.下列不是Java关键字的是(
D
A、finalB、finallyC、nullD、sizeof
21.以下(
)是java.io包中的一个兼有输入输出功能的类。
A、Object
B、Serializable
C、RandomaccessFile
D、java.io中不存在这样的类
22.下面哪个语句正确地声明一个整型的二维数组?
D
)
Ainta[][]=newint[][];
Binta[100][100]=newint[][];
Cint[]a[]=newint[100][100];
Dinta[][]=newint[100][100];
23.编译JavaApplication源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为(
B
A.javaB.class
C.htmlD.exe
24.为读取的内容进行处理后再输出,需要使用下列哪种流?
AFilestreamBPipestreamCRandomstreamDFilterstream
25.下列方法中可以用来创建一个新线程的是。
(
C
A实现java.lang.Runnable接口并重写start()方法
B实现java.lang.Runnable接口并重写run()方法
C继承java.lang.Thread类并重写run()方法
D实现java.lang.Thread类并实现start()方法
26.给出如下初始化语句
Strings1=newString(“Hello”);
Strings2=newString(“there”);
Strings3=newString();
以下哪种操作是合法的?
A
As3=s1+s2;
Bs3=s1-s2;
Cs3=s1&
s2;
Ds3=s1&
&
27.容器Panel和Applet缺省使用的布局编辑策略是(
ABorderLayoutBFlowLayout
CGridLayoutDCardLayout
28.给出如下代码:
classTest{
privateintm;
publicstaticvoidfun(){
//somecode...
}
如何使成员变量m被函数fun()直接访问?
A将privateintm改为protectedintm
B将privateintm改为publicintm
C将privateintm改为staticintm
D将privateintm改为intm
29.以下有关类的继承的说明中正确的是:
A子类能直接继承父类所有的非私有属性,也可通过接口继承父类的私有属性
B子类只能继承父类的方法,不能继承父类的属性
C子类只能继承父类的非私有属性,不能继承父类的方法
D子类不能继承父类的私有属性
30.以下语句有语法错的是:
A
A
intx=1;
y=2;
z=3Bfor(intx=10,y=0;
x>
0;
x++);
while(x>
5);
Dfor(;
;
二、简答题
1、请说明this,super,final各自的作用。
答:
this:
①指代调用方法的当前对象;
②在构造函数内使用this用于指代另外一个构造函数
super:
提供了一种调用父类构造函数的方法。
final:
使得某个变量值只能被引用,而不能修改。
2、试解释方法重构和方法重载的区分。
P63
3、请解释面向对象程序设计相关的几个概念:
继承、多态、重载。
继承:
继承是一种联结类的层次模型,并且允许和鼓励类的重用,它提供了一种明确表述共性的方法。
对象的一个新类可以从现有的类中派生,这个过程称为类继承。
新类继承了原始类的特性,新类称为原始类的派生类(子类),而原始类称为新类的基类(父类)。
派生类可以从它的基类那里继承方法和实例变量,并且类可以修改或增加新的方法使之更适合特殊的需要。
多态性:
多态性是指允许不同类的对象对同一消息作出响应。
多态性包括参数化多态性和包含多态性。
多态性语言具有灵活、抽象、行为共享、代码共享的优势,很好的解决了应用程序函数同名问题。
重载方法:
在一个类定义中,可以编写几个同名的方法,但是只要它们的签名参数列表不同,Java就会将它们看做唯一的方法。
简单的说:
一个类中的方法与另一个方法同名,但是参数表不同,这种方法称之为重载方法。
4、请说明抽象类和接口的异同点。
P95
5、实例变量与局部变量的区别
P50
三、阅读程序
1.以下程序段的输出结果为56789。
publicclassTestArray
publicstaticvoidmain(Stringargs[]){
inti,j;
inta[]={5,9,6,8,7};
for(i=0;
i<
a.length-1;
i++){
intk=i;
for(j=i;
j<
a.length;
j++)
if(a[j]<
a[k])k=j;
inttemp=a[i];
a[i]=a[k];
a[k]=temp;
}
for(i=0;
i<
a.length;
i++)
System.out.print(a[i]+"
"
System.out.println();
}
2.编程填空(将横线上所缺的内容补充完整)
下列程序中(Assign.java),指定变量b=50为字节类型,变量f=0.55F为单精度实型,变量k=0xfffL为64位整型,并将该三个变量打印输出,请将程序补充完整。
(每空1分)
importjava.io.*;
public___class____Assign
publicstaticvoidmain(Stringargs[])
___byte____b=50;
___float__f=0.55F;
___long____k=0xfffL;
System.out.println("
b="
+b);
f="
__+f____);
k="
+k);
}
3.写出以下程序的运行结果。
noException
Finally
Catch
publicclassTryCatchFinally{
staticvoidProc(intsel){
try{
if(sel==0){
System.out.println("
noException"
return;
elseif(sel==1){inti=0;
intj=4/i;
}
catch(ArithmeticExceptione){
System.out.println("
Catch"
catch(Exceptione){
Willnotbeexecuted"
finally{
finally"
}
publicstaticvoidmain(Stringargs[]){
Proc(0);
Proc
(1);
4.阅读以下程序,写出输出结果AnimalDog。
classAnimal{
Animal(){System.out.print("
Animal"
publicclassDogextendsAnimal{
Dog(){System.out.print("
Dog"
publicstaticvoidmain(String[]args){
Dogsnoppy=newDog();
5.阅读以下程序:
classExp1
publicstaticvoidmain(String[]args)
{
Strings,s1="
;
charc;
s=args[0];
for(inti=0;
i<
s.length();
i++)
{
c=s.charAt(i);
if(c>
='
a'
&
c<
z'
){
s1=s1+Character.toUpperCase(c);
}else{
s1=s1+Character.toLowerCase(c);
System.out.println(s1);
若在dos命令行输入:
javaExp1DEFabc,则输出为defABC。
6.阅读下面的程序,并回答问题。
importjava.io.*;
publicclassTest{
publicstaticvoidmain(Stringargs[])throwsIOException{
BufferedReaderbuf=newBufferedReader(
newInputStreamReader(System.in));
while(true){
Stringstr=buf.readLine();
if(str.equals("
quit"
))
break;
intx=Integer.parseInt(str);
System.out.println(x*x);
编译运行上面的程序:
1)从键盘输入10,回车后输出的结果为100。
2)从键盘输入exit,回车后程序能正确执行吗?
为什么?
不能,exit不能装换成数字
四、编程题
1、写出一个Point(点)类,该类具有x,y(表示点的横、纵坐标)两个属性,并定义两个构造方法,一个无参数,将x,y均设置为0,另一对坐标值为参数,设置x,y为给定坐标值。
在类中设计一个show方法,实现输出该类对象的坐标值。
packagezjw;
publicclassPoint{
intx,y;
Point()
x=0;
y=0;
Point(inta,intb)
this.x=a;
this.y=b;
publicvoidshow()
该类x坐标值为"
+this.x);
该类y坐标值为"
+this.y);
publicclasstest1{
publicstaticvoidmain(String[]args){
Pointp=newPoint(1,16);
p.show();
2、假设我们从键盘输入一段英文,统计这段文字中单词的个数,并输出其中由四个字母组成的单词。
importjava.util.*;
publicclasstest2{
/*从键盘中读取一行字符串*/
publicstaticStringreadString()
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in),1);
Stringstring="
try
string=br.readLine();
}catch(IOExceptionex)
System.out.println(ex);
returnstring;
//TODO自动生成方法存根
Stringline;
StringTokenizertoken;
intnum=0;
System.out.print("
请输入一行字符:
line=readString();
token=newStringTokenizer(line);
inttl=token.countTokens();
String[]str=newString[tl];
for(inti=0;
tl;
str[i]=token.nextToken();
System.out.println("
您输入的文字中单词的个数为:
+str.length);
有四个字母组成的单词为:
str.length;
if(str[i].length()==4)
{
System.out.println(str[i]);
3、从键盘输入一行文本,显示其中各元音字母出现的次数。
publicclassTest3{
Stringline;
line=readString();
\r"
intnuma=0,numi=0,nume=0,numu=0,numo=0;
intlength=line.length();
for(inti=0;
length;
switch(line.charAt(i)){
case'
:
A'
numa++;
i'
I'
numi++;
u'
U'
numu++;
e'
E'
nume++;
o'
O'
numo++;
default:
元音a出现的次数为:
+numa);
元音i出现的次数为:
+numi);
元音e出现的次数为:
+nume);
元音u出现的次数为:
+numu);
元音o出现的次数为:
+numo);
4、编写程序计算12+22+32+42+……+972+982+992+1002的值并输出。
publicclasstest4{
publicstaticvoidmain(String[