完整word版java程序设计期末考试A卷.docx
《完整word版java程序设计期末考试A卷.docx》由会员分享,可在线阅读,更多相关《完整word版java程序设计期末考试A卷.docx(16页珍藏版)》请在冰点文库上搜索。
![完整word版java程序设计期末考试A卷.docx](https://file1.bingdoc.com/fileroot1/2023-5/23/361b58d1-fadb-4aa6-94db-5bb1b72da7cd/361b58d1-fadb-4aa6-94db-5bb1b72da7cd1.gif)
完整word版java程序设计期末考试A卷
河南大学2012~2013学年第一学期期末考试
Java程序设计试卷A卷
考试方式:
闭卷 考试时间:
120分钟 卷面总分:
100分
题号
一
二
三
四
总成绩
合分人
得分
得分
评阅人
一、单项选择题(每个小题2分,共40分)
1.关于main方法,以下描述哪项是合法的()?
A、publicvoidstaticmain()
B、publicstaticvoidmain(Stringa[])
C、main方法是JavaApplet程序执行的入口。
D、main方法中可以用类名调用该类的实例方法。
2.关于如下程序的描述哪个是正确的?
()
publicclassPerson{
staticdoublearr[]=newdouble[5];
publicstaticvoidmain(Stringargs[]){
System.out.println(arr[0]);
}
}
A、编译将产生错误B、编译时正确,但运行时将产生错误
C、正确,输出0.0D、正确,输出 null
3.假设A类有如下定义,设a是A类的一个实例,下列语句调用哪个是错误的?
()
classA{
staticinti;
Strings;
staticvoidmethod1(){}
voidmethod2(){}
}
A、System.out.println(a.i);B、a.method1();C、A.method1();D、A.method2()
4.创建一个标识有“关闭”标签的语句是()。
A、TextFieldb=newTextField(“关闭”);
B、Labelb=newLabel(“关闭”);
C、Checkboxb=newCheckbox(“关闭”);
D、Buttonb=newButton(“关闭”);
5.对于子类的构造函数说明,下列叙述中错误的是()。
A、子类可以继承父类的构造函数。
B、子类中调用父类构造函数不可以直接书写父类构造函数,而应该用super();。
C、用new创建子类的对象时,将先执行继承自父类的无参构造函数,然后再执行自己的构造函数。
D、子类的构造函数中不可以调用其他函数。
6.下列哪个选项是错误的。
()
A、一个文件中只能有一个publicclass。
B、一个文件中可以有多个类。
C、一个类中可以有两个main方法。
D、main方法必须是public的。
7.类ABC定义如下:
1.publicclassABC{
2.publicdoublemax(doublea,doubleb){}
3.
4.}
将以下哪个方法插入行3是不合法的。
()
A、publicfloatmax(floata,floatb,floatc){}
B、publicdoublemax(doublec,doubled){}
C、publicfloatmax(floata,floatb){}
D、privateintmax(inta,intb,intc){}
8.以下哪项是错误的()。
A、JPanel中不能包含按钮。
B、Frame中可以设置Panel。
C、Applet中可以包含按钮。
D、Dialog中不可以设置菜单条。
9.在Applet中,方法执行的顺序是?
()
A、init(),start(),paint(),stop(),destroy().
B、init(),paint(),start(),stop(),destroy().
C、paint(),start(),stop(),destroy().
D、init(),start(),stop(),destroy(),paint().
10.以下哪个方法用于定义线程的执行体?
()
A、 start()B、init()C、run()D、synchronized()
11.当使包含applet程序的页面从最小化恢复时,以下选项中的哪个方法将被执行?
()
A、paint()B、start()C、destroy()D、stop()
12.A是抽象父类或接口,B ,C派生自A,或实现A,现在Java源代码中有如下声明:
1.Aa0=newA();
2.A a1=newB();
3.Aa2=newC();
问以下哪个说法是正确的?
()
A、只有第1行不能通过编译
B、第1、2行能通过编译,但第3行编译出错
C、第1、2、3行能通过编译,但第2、3行运行时出错
D、第1行、第2行和第3行的声明都是正确的
13.以下哪个接口的定义是正确的?
()
A、interfaceB
{publicabstractvoidprint(){};}
B、interfaceB
{staticvoidprint();}
C、abstractinterfaceBextendsA1,A2//A1、A2为已定义的接口
{privateabstractvoidprint();}
D、interfaceB
{voidprint();}
14.关于Socket通信编程,以下描述正确的是:
()
A、客户端通过newServerSocket()创建TCP连接对象
B、客户端通过TCP连接对象调用accept()方法创建通信的Socket对象
C、客户端通过newSocket()方法创建通信的Socket对象
D、服务器端通过newServerSocket()创建通信的Socket对象
15. 关于数据库连接的程序,以下哪个语句的注释是错误的()
A、Class.forName(“com.mysql.jdbc.Driver”);//指定MySQLJDBC驱动程序
B、Stringurl=”jdbc:
mysql:
//localhost:
3306/student”;//指定驱动程序与数据源的连接
C、db.executeUpdate(sql);//用于返回查询结果
D、while(rs.next())//用于遍历查询结果中的记录
16.关于异常的编程,以下描述错误的是:
()
A、在有除法存在的代码处,抛不抛出异常均可
B、inti=Integer.parseInt(”123a”);将产生IDberFormatException
C、inta[]=null;a[0]=1;将产生ArraylndexOutOfBoundsException
D、输入输出流编程中,读和写时都必须抛出IOException
17.在main()方法中给出的字节数组,如果将其显示到控制台上,需要()
A.标准输出流System.out.println()。
B.建立字节输出流。
C.建立字节输入流。
D.标准输入流System.in.read()。
18.在main()方法中给出的整型数组,如果将其写到一个文件中,需要()
A.标准输出流System.out.println()。
B.建立数据字节输出流。
C.建立数据字节输入流。
D.标准输入流System.in.read()。
19.一个文件中的数据要在控制台上显示,首先需要()
A使用标准输出流System.out.println()。
B建立文件输出流。
C建立文件输入流。
D标准输入流System.in.read()。
20.一个文件中的字符要写到另一个文件中,首先需要()
A使用标准输出流System.out.println()。
B建立文件字符输出流。
C建立文件字符输入流。
D标准输入流System.in.read()。
得分
评阅人
二、读程序,给结果(共27分)
1.设有数组定义:
inta[]={10,50,30,40,80,60,20,30,90,20};
将输出结果填写在输出语句后的注释中。
(本题5分)
publicintget(intscore[]){
m=score[0];
for(inti=0;iif(mm=score[i];
}
}
returnm;
}
a[]带入get方法后,m取值为()
2.写出以下程序的运行结果,填写在每个输出语句后面的注释中。
(每空1.5分,共18分)
publicclassATest{
publicstaticvoidmain(Stringargs[]){
Subsub=newSub();
System.out.println(sub.x);//()
System.out.println(sub.n);//()
System.out.println(sub.method1());//()
System.out.println(sub.method2());//()
Supersupsub=newSub();
System.out.println(supsub.x);//()
System.out.println(supsub.n);//()
System.out.println(supsub.method1());//()
System.out.println(supsub.method2());//()
Supersup=newSuper();
System.out.println(sup.x);//()
System.out.println(sup.n);//()
System.out.println(sup.method1());//()
System.out.println(sup.method2());//()
}
}
classSuper{
intx=1,y=2;
staticintn=50;
intmethod1(){
return(x>y)?
x:
y;
}
staticintmethod2(){
returnn--;
}
}
classSubextendsSuper{
intmethod1(){
return(xx:
y;
}
staticintmethod2(){
returnn++;//static用的父类的
}
}
3.写出以下程序的运行结果。
(每空2分,共4分)
classFirst{
First(){
System.out.println("10");
}
}
publicclassSecondextendsFirst{
Second(){
System.out.println("20");
}
publicstaticvoidmain(String[]args){
Secondmine=newSecond();
}
}
运行结果:
()
()
得分
评阅人
三、补程序(13分)
图形用户界面程序填空。
界面效果:
姓名、学号两个标签之后两个文本行。
在文本行填入姓名和学号后,单击按钮“提交”,学号从上往下掉,姓名从左往右移动。
注意有的空需将不完整的Java保留字补齐(每空1分)
importjava.applet.___;//
(1)
importjava.awt.*;
importjava.awt._____.ActionEvent;//
(2)
publicclassNameDropextendsAppletimplementsRunnable,____{//(3)
privateintx=0;
privateinty=0;
private_____t;//(4)
privatebooleanb=false;
privateButtonbutton;
privateTextFieldtextFieldName;
privateTextFieldtextFieldID;
privateStringname;
privateStringID;
privateLabelLabelName;
privateLabelLabelID;
publicvoid___(){//(5)
this.setSize(300,300);
button=newButton("提交");
textFieldName=newTextField(10);
textFieldID=newTextField(10);
button.add____________(this);//(6)
LabelName=newLabel("姓名");
LabelID=newLabel("学号");
this.add(button);
this.add(LabelName);
this.add(textFieldName);
this.add(LabelID);
this.add(textFieldID);
}
publicvoidstart(){
if(t==null){
t=newThread(_________);//(7)
t.start();
}
}
publicvoidstop(){
if(t!
=null){
t.interrupt();
t=null;
}
}
publicvoidpaint(Graphics___){//(8)
if(b){
x=x+1;
y=y+1;
g.drawString(name,x,80);
g.drawString(ID,50,y);
}
}
publicvoidrun(){
while(t!
=null){______();//(9)
try{
t._______(20);//(10)
}______catch(InterruptedExceptione){//(11)
break;
}
}
}
publicvoidactionPerformed(ActionEvente){
if(e.________()==button){//(12)
b=true;
name=textFieldName.getText();
ID=textFieldID._________();//(13)
}
}
得分
评阅人
四编程题(20分)
学生(Student)评奖方法(Award)有多种,比如:
励志奖(award1)、优秀学生干部(award2)等;学生类别也有多种,比如:
有一本(Student1)、三本(Strudent3)等。
要求编写学生评奖系统,评奖方法可以扩展,学生身份可以扩展。
(7个类或接口,最后Test类2分,其他每个类或接口3分)
输出:
学生张三采用:
打分方法1
学生张三采用:
打分方法2
学生李四采用:
打分方法1
学生李四采用:
打分方法2
学号:
姓名:
年级:
专业:
…………………………………密………………………………封………………………………线…………………………………
河南大学2012-2013学年第一学期期末考试
Java程序设计试卷A卷参考答案与评分标准
(卷面总分:
100分)
一、单项选择题(每小题2分,共20小题,总计40分)
BCDBACBAACAADCCCABCC
二、读程序,给结果(共27分)
1、90
2、1,50,1,50,1,51,1,51,1,50,2,50
3、10,20
三、补程序(13分)
(1)Applet
(2)event(3)ActionListener(4)Thread(5)init()(6)ActionListener(7)this(8)g(9)start()(10)sleep()(11)catch(12)getSource(13)getText()
四、编程题(20分)
publicinterfaceAward{
publicabstractvoidscore();
}
publicclassAward1implementsAward{
publicvoidscore(){
System.out.println("打分方法1");
}
}
publicclassAward2implementsAward{
publicvoidscore(){
System.out.println("打分方法2");
}
}
publicabstractclassStudent{
privateStringname;
Awardaw;
publicabstractvoidaward();
publicvoidsetAward(Awardaw){
this.aw=aw;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
}
publicclassStudent1extendsStudent{
publicvoidaward(){
aw.score();
}
}
publicclassStudent2extendsStudent{
publicvoidaward(){
aw.score();
}
}
publicclassTest{
publicstaticvoidmain(Stringargs[]){
Studenta;
a=newStudent2();
a.setName("张三");
a.setAward(newAward1());
System.out.println("学生"+a.getName()+"采用:
");
a.award();
a.setAward(newAward2());
System.out.println("学生"+a.getName()+"采用:
");
a.award();
a=newStudent1();
a.setName("李四");
a.setAward(newAward1());
System.out.println("学生"+a.getName()+"采用:
");
a.award();
a.setAward(newAward2());
System.out.println("学生"+a.getName()+"采用:
");
a.award();
}
}