全国高等教育自学考试Java语言程序设计一考试试题.docx
《全国高等教育自学考试Java语言程序设计一考试试题.docx》由会员分享,可在线阅读,更多相关《全国高等教育自学考试Java语言程序设计一考试试题.docx(10页珍藏版)》请在冰豆网上搜索。
![全国高等教育自学考试Java语言程序设计一考试试题.docx](https://file1.bdocx.com/fileroot1/2023-2/23/48df7d01-e513-427f-9ba9-4e4b609478e9/48df7d01-e513-427f-9ba9-4e4b609478e91.gif)
全国高等教育自学考试Java语言程序设计一考试试题
Companynumber【1089WT-1898YT-1W8CB-9UUT-92108】
全国高等教育自学考试Java语言程序设计一考试试题
全国2009年10月高等教育自学考试
Java语言程序设计
(一)试题
课程代码:
04747
一、单项选择题(本大题共10小题,每小题1分,共10分)
在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。
错选、多选或未选均无分。
1.下面供选字符序列中,不属于Java语言关键字的是()
A.gotoB.null
C.falseD.native
2.以下程序代码的输出结果是()
(x>>1);
A.36B.
C.37D.true
3.Java语言中,在类定义时用final关键字修饰,是指这个类()
A.不能被继承B.在子类的方法中不能被调用
C.能被别的程序自由调用D.不能被子类的方法覆盖
4.以下是关于字符串运算的代码,执行该代码段的输出结果是()
Strings=″09″,sl,s2;
sl=
(2);s2=(2,5)(s1+s2);
A.0122345B.2345
C.012234D.234
5.以下是关于FlowLayout布局组件排列顺序的叙述,正确的是()
A.从上到下排列B.从左到右排列
C.从下到上排列D.从右到左排列
6.程序执行方法showOpenDialog(),能打开“打开文件对话框”,如果该方法的返回值是,则用户执行的动作是()
A.对话框非正常关闭B.按下“打开/保存”按钮
C.按下“撤销”按钮D.重新输入了一个文件名
7.设已经有Graphics2D对象g2d,Rectangle2D对象r,绘制对象r的代码是()
A.(r)B.(r)
C.()D.()
8.在以下供选择的方法中,能让线程从阻塞状态恢复到就绪状态的方法是()
A.start()B.init()
C.resume()D.run()
9.在以下供选择的方法中,不能用于文件随机访问的方法是()
A.readChar()B.readLong()
C.readInteger()D.writeChars()
10.某程序利用网址参数创建URL对象url,接着希望利用对象url获得URLConnection对象,则这个url对象要调用的方法是()
A.connection()B.URLConnection()
C.getConnection()D.openConnection()
二、填空题(本大题共10小题,每小题2分,共20分)
请在每小题的空格中填上正确答案。
错填、不填均无分。
11.一个应用程序必须在某个类中定义的方法是______。
12.import语句的格式是______。
13.在面向对象语言中,对象之间的交互通过______实现。
14.设有两个字符串对象str1和str2,则表达式“strl==str2”的意义是判别字符串strl和str2______。
15.一个基于Swing的应用程序可能在任何平台上都会有相同的______。
16.处理键盘事件的Java程序,要实现的接口是______。
17.Java语言约定,坐标原点位于绘图区域的______。
18.Java程序中,在临界段中使用______方法,使执行该方法的线程等待。
19.BufferedWriter类对象能按行输入文件的内容,按行输入的方法是______。
20.在包中有InetAddress类的定义,Java程序中的InetAddress类对象存储的内容是______。
三、简答题(本大题共6小题,每小题3分,共18分)
21.请写出实现计算y=|x|的if语句。
22.以下代码定义了一个类,请指出其中三条不合法的代码行(行号参见注释)。
classTest22{18磅ddItemListener(this);
}
}
publicvoiditemStateChanged(ItemEvente){
for(inti=0;i<;i++){
if(box[i]._______){
(box[i].getLabel()+"被选中!
");
}
}
}
}
30.用getImage()方法和drawImage()方法能加载和显示图像。
以下程序加载的是seattle.jpg文件,并假定该文件与包含这个小应用程序的HTML文件在同一个目录下。
import.*;import.*;
publicclassSimpleImageLoadextendsApplet{
Imageimg;
publicvoidinit(){
img=getImage(______,"");
}
publicvoidpaint(Graphicsg){
(img,0,0,______);
}
}
31.以下程序段定义的类ShareDataManager用于管理多个线程共享数据data。
为了对data的取、存和修改操作保持完整,多线程在data上的操作有互斥要求;另外,限制线程对data的修改不能让data为负数,所以多线程在data上的操作还有同步要求。
为此,程序为管理data上的操作定义成类,以下是管理共享数据data的类ShareDataManager的代码。
classShareDataManager{
intdata;
ShareDataManager(intinit){data=init;}
publicintgetData(){returndata;}
privatevoidputData(intnewValue){data=newValue;}
synchronizedvoidmodiData(intdelta){
if(delta>=0){putData(getData()+delta);
}else{
while(______<0){
try{wait();}catch(InterruptedExceptione){}
}
putData(getData()+delta);
}
______;
}
}
五、程序分析题(本大题共5小题,每小题4分,共20分)
32.阅读下列程序,请写出该程序的输出结果。
classTree{
privateStringname;publicbooleanflower;
publicintbirthYear;
Tree(Stringn,booleanf,inty){name=n;flower=f;birthYear=y;}
publicvoidsetName(Stringn){name=n;}
publicStringgetName(){returnname;}
publicvoidprintTree(Stringstr){
(str)("Name:
"+name);
("BirthYear:
"+birthYear);
("Flower:
"+flower);
}
}
classPineTreeextendsTree{
publicbooleanconiferous=true;
PineTree(Stringn,booleanf,inty,booleanc){super(n,f,y);coniferous=c;}
publicvoidprintTree(Stringstr){
super,printTree(str);
("Coniferous:
"+coniferous);
}
}
classTest32{
publicstaticvoidmain(String[]args){
TreefOb=newTree("MayFlower",true,1980);
PineTreesOb=newPineTree("Pine",false,2000,true);
("fOb:
");("sOb:
");
}
}
33.阅读下列程序,请写出该程序的输出结果。
classTest33{
staticvoids(intb[],intk){
inti,j,t;
for(i=1;ifor(t=b[i],j=i-1;j>=0&&t
b[j+l]=b[j];
b[j+1]=t;
}
}
publicstaticvoidmain(String[]args){
inti,a[]={6,12,7,11,5};
s(a,5);
for(i=0;i<;i++)(a[i]+"");
System.out.Println();
}
}
34.阅读下列程序,请写出该程序的功能。
import.*;import.*;
publicclassTest34extendsAppletimplementsActionListener{
JTextFieldtext;intr;JPanelpanel;
publicvoidpaint(Graphicsg){
Graphicsgc=();
(0,0,(),());
();(10,10,r,r);
}
publicvoidinit(){
text=newJTextField(10);panel=newJPanel();
setSize(200,100);setLayout(newGridLayout(2,1));
add(text);add(panel);(this);
}
publicvoidactionPerformed(ActionEvente){
if(()==text){
r=(());
repaint();
}
}
}
35.阅读下列程序,请回答以下问题:
(1)该程序的菜单条中共有几个菜单项
(2)单击哪个菜单项,可以打开一个对话框
(3)该对话框是强制型还是非强制型
(4)该对话框中显示的是什么内容
Import.*;import.*;
classMyDialogextendsJDialog{
MyDialog(JFrameF,Strings){
super(F,s,false);Datedate=newDate();
Stringt=();JLabeltext=newJLabel(t);
add(text);setSize(200,100);setVisible(true);
}
}
publicclassMenuDemoextendsJFrameimplementsActionListener{
JMenuBarmenubar;JMenuaction;
JMenuItemshow,set,quit;
publicMenuDemo(){
menubar=newJMenuBar();setJMenuBar(menubar);
action=newJMenu(''操作'');(action);
show=newJMenuItem(''显示''),(show);
set=newJMenuItem("设置");(set);
();quit=newJMenuItem("退出");
(quit);(this);
(this);(this);
setSize(300,300);setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(()==show){MyDialogdiag=newMyDialog(this,"信息");}
elseif(()==set){("菜单演示");}
elseif(()==quit){(0);}
}
publicstaticvoidmain(String[]args){newMenuDemo();}
}
36.阅读以下程序,请写出该程序的输出结果。
classCurrentThreadDemo{
publicstaticvoidmain(Stringargs[]){
Threadt=newThread()("Currentthread");
("MyThread")("Afternamechange");
try{for(intn=3;n>0;n--){
(n);(1000);
}
}catch(InterruptedExceptione){
("Mainthreadinterrupted");
}
}
}
六、程序设计题(本大题共2小题,每小题6分,共12分)
37.编写方法intsearchMaxNumIndex(int[]a),寻找已知数组中最大数的下标并返回。
38.以下程序的界面有一个按钮button、一个文本区textA和一个文本框textF。
程序运行时,在文本区中输入数字序列,单击按钮,则在文本框中显示数字序列的和。
以下是要求你编写的actionPerformed(ActionEvente)方法的部分代码。
publicvoidactionPerformed(ActionEvente){
if(()==button){
Strings=();doublesum=0;
StringTokenizerfenxi=newStringTokenizer(s,",\n");
//请在以下位置编写代码