软件学院面向对象程序设计期末B卷.docx
- 文档编号:25165773
- 上传时间:2023-06-05
- 格式:DOCX
- 页数:12
- 大小:41.02KB
软件学院面向对象程序设计期末B卷.docx
《软件学院面向对象程序设计期末B卷.docx》由会员分享,可在线阅读,更多相关《软件学院面向对象程序设计期末B卷.docx(12页珍藏版)》请在冰豆网上搜索。
软件学院面向对象程序设计期末B卷
一、选择题(30分)
说明:
每题2分,只有1个正确答案,请将正确答案填写在下面表格中。
题号
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
答案
1.WhichofthefollowingstatementsiscorrectaboutJavapackages?
A.Apackagemaycontainunlimitednumberofnestedsub-packages.
B.ApackageisacollectionofrelatedJavasourceprogram.
C.Usingtheimportstatementcanincludealltheclassesintothecurrentprogramfromaspecifiedpackageanditssub-packages.
D.Ifthereisnopackagestatementused,thecurrentclasswillnotbeinanypackage.
2.WhichoneisthewrongstatementaboutJavaconstructors?
A.Thenameofaconstructormustbethesameasitsclass’sname.
B.Aconstructorhasnoreturnvalueandcannotbemodifiedbyvoid.
C.Aconstructoroftheparentclasscannotbeinheritedbyitssub-classes.
D.Allconstructorsmustbemodifiedbypublic.
3.Givingthecodebellow:
classTest{
privateintm;
publicstaticvoidfun(){/*somecode...*/}
}
Howtomakethemembervariablemaccessibleformethodfun()?
A.change"privateintm"to"protectedintm"
B.change"privateintm"to"publicintm"
C.change"privateintm"to"staticintm"
D.change"privateintm"to"intm"
4.Whichofthefollowingfunctionsisanoverloadingfunctionof"publicvoidexample(){...}"?
A.publicvoidexample(){...}
B.publicintexample(){...}
C.publicvoidexample2(){...}
D.publicintexample(intm,floatf){...}
5.InJava,aclassmayhavemanydifferentmethodswiththesamename.Thenumber,type,sequencesofargumentsinthesemethodsaredifferent,andthereturnvaluecanbedifferentaswell.Whatdowecallthisfeatureintermsofobject-orientedprogramming?
A.HidingB.Overriding
C.OverloadingD.ThisfeatureisnotsupportedinJava
6.Howtoexecutethefollowingprogram?
publicclassTest{
publicstaticvoidmain(Stringargs[]){
System.out.println(args[0]);
}
}
A.javaTest.classB.javaTest
C.javaTestaStringD.javacTest
7.Ifacontainerhasbeenresized,whichofthefollowinglayoutmanagerdidnotchangetheinternalcomponents'size?
A.CardLayoutB.FlowLayout
C.BorderLayoutD.GridLayout
8.Whichistherightstatementaboutexceptionhandling?
A.Injava,allexceptionsarenecessarytobecaughtandhandled.
B.The“catch”statementcatchesexceptionbytype-matching.
C.Inthe“try-catch-finally”structure,theprogramwillexitafterexceptionhandling.
D.Exceptionisakindoferrors,anditshouldbeabsolutelyavoidedinprograms.
9.Thefollowingstatementsareabouttype-casting,whichoneiscorrect?
A.Areferencevariableofaclasscanonlybeassignedtoanobjectofitsfirstlevelsub-classesofthisclass.
B.Anobjectcannotbecastedtothetypeofanotherclasswhichhasnoinheritancerelationshipwiththeobject’soriginalclass.
C.Achildclass’sreferencevariablecanbeassignedtoanobjectofitsparentclass.
D.Thereisonlyexplicitcasting,butnoimplicitcasting.
10.BothclassTeacherandStudentarethesub-classesofPerson.
Personp;Teachert;Students;//assumep,tandsarenotnull
if(tinstanceofPerson){s=(Student)t;}
Whichstatementaboutthelastlineofexpressioniscorrect?
A.AnewStudentobjectwillbecreated.
B.Thetype-castingiscorrect.
C.Theexpressionisincorrect.
D.Thereisnosyntaxerrorbutwillgenerateruntimeerror.
11.Accordingtothecodebelow,whichstatementiscorrect?
publicclassTest{
staticObjecto;
publicstaticvoidmain(Stringargs[]){
System.out.println(o);
}
}
A.Generatescompileerror.
B.CompilesOK,buthasruntimeerrors.
C.Outputszero.
D.Outputs“null”.
12.Accordingtothecodebelow,selectthestatementwhichisfalse.
Strings="Hello";
Strings1=newString("Hello");
Strings2=s1.intern();
Strings3="Hello";
A.s1==sB.s2==s
C.s==s3D.s2==s3
13.Thearraydefinitioncodeisgivenbelow,whichstatementiscorrect?
String[][]s=newString[10][];
A.Thedefinitionofarraysisillegalinsyntax.
B.sisa10×10two-dimensionalarray.
C.Allelementsinsare"".
D.sisanarrayoftenarrays.
14.Whichisthecorrectoutputaccordingtotheprogramgivenbellow?
publicstaticvoidmain(String[]args){
Scannerscanner=newScanner("thisisonethatistwo");
scanner.useDelimiter("is");//thereisaspacebefore"is"
while(scanner.hasNext()){
System.out.print(scanner.next());
}
}
A.thisonethattwoB.thonethattwo
C.thonethattwoD.thisisonethatistwo
15.Thefile“empty.txt”doesnotexistbefore,whatitscontentwillbeafterexecutingthefollowingcode.
publicstaticvoidmain(String[]args)throwsFileNotFoundException{
PrintWriterpr=newPrintWriter(newFile("empty.txt"));
pr.print("one\ttwo");
pr.append("\n1\t2");
pr.close();
}
A.onetwoB.one\ttwo
121\t2
C.one\ttwo\n1\t2D.onetwo12
二、改错题(20分)
说明:
写出每段代码的错误原因并改正错误,每小题4分,说明原因和改正各2分。
1.classFirst{}
importjava.io.*;
packagemypackage;
classSecond{}
2.classA{
Stringname;
publicA(Strings){name=s;}
}
classBextendsA{
intid;
publicB(inti){id=i;}
}
3.classAlpha{
privatevoidm(){}
publicvoidp(){}
}
classBetaextendsAlpha{
publicvoidm(){}
privatevoidp(){}
}
4.interfaceBase{
voidm();
voidn();
}
classChildimplementsBase{
publicvoidm(){
System.out.println("thisismethodm");
}
}
5.publicclassBextendsA{
finalvoidincrease(){
value+=2;
}
}
classA{
intvalue=0;
finalvoidincrease(){
value+=1;
}
}
三、程序阅读题(20分)
说明:
阅读下面程序并写出它们的输出结果,每小题5分。
1.Theprogramisasbelow:
classA{
inth=1;
publicA(inth){
h=h;
System.out.println(this.h);
this.h=h;
System.out.println(this.h);
}
publicstaticvoidmain(String[]args){
Aa=newA
(2);
}
}
2.Theprogramisasbelow:
classBase{
publicBase(){
System.out.println("Whatapleasure!
");
}
publicBase(Strings){
this();
System.out.println("Iam"+s+"!
");
}
}
publicclassChildextendsBase{
publicstaticvoidmain(Stringargs[]){
Childt=newChild("Mike");
}
publicChild(Strings){
super(s);
System.out.println("Howdoyoudo?
");
}
publicChild(){
this("IamTom");
}
}
3.Theprogramisasbelow:
classDivTest{
publicstaticvoidmain(String[]args){
intr,n,d;
n=10;d=0;
try{
r=n/d;
System.out.println("r="+r);
}catch(ArithmeticExceptione){
System.out.println("Divide0exception!
");
}finally{
System.out.println("Calculationcomplete!
");
}
System.out.println("Programfinish!
");
}
}
4.Analyzetheprogrambellow,andexplainitseffect.
publicclassMyFrameextendsJFrame{
JButtonb1,b2;
publicMyFrame(){
ActionListenera=newActionListener(){
publicvoidactionPerformed(ActionEventevt){
if(evt.getSource()==b1){
b1.setEnabled(false);
b2.setEnabled(true);
}else{
b1.setEnabled(true);
b2.setEnabled(false);
}
}
};
setLayout(newFlowLayout());
b1=newJButton("1");b1.addActionListener(a);add(b1);
b2=newJButton("2");b2.addActionListener(a);add(b2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(150,100);
setVisible(true);
}
publicstaticvoidmain(String[]args){
newMyFrame();
}
}
四、应用设计题(6分)
Thefollowingclassesareapartoftheclassesfoundedinacompany’spersonnelmanagementsystem,findouttheirrelationshipsandillustrateusingaUMLclassdiagram.
Employee,long-ternemployee,temporalemployee,manager,temporalsalesman.
五、程序设计题(24分)
说明:
按照题目要求编写下面两段程序。
1.Writeajavaapplicationprogramcontainingtheseclasses:
Person,Student,TestStudent.Thedetailsare:
⑴ ClassPerson
① Properties
name:
String
sex:
char
id:
String
phone:
String
email:
String
②Methods
Person(Namename,charsex,Stringid):
constructor
StringgetId()
voidsetEmail(Stringemail)
voidsetPhone(Stringphone)
StringtoString():
outputsaperson’sinformation
⑵ ClassStudent
Asub-classderivedfromPerson,morepropertiesareadded:
① Properties
sNo:
long
sClass:
String
② Methods
Student(longsNo,Stringname,charsex,Stringid):
constructor
setClass(StringsClass)
StringtoString():
outputsastudent’sinformation
⑶ ClassTestStudent
Aclassusedasthemainclasstotestthefunctions.
① usethefollowinginformationtocreateastudentobject,aStudent.
Name:
GuoYang
Sex:
male
ID:
22033198807070333
sNo.:
2004002
② setotherinformationtoaStudent.
E-mail:
yangguo@
Phone:
88078549
③ outputalltheinformationofaStudent.
2.Calculatethesumareaofcircles.(14points)
Therequirementsare:
⑴DefineaninterfaceShape,andano-argmethodgetArea()thatreturnsdoublevalue.
⑵DefineaclassCircleimplementingtheShapeinterfaceabove,withintheclassthereisadoublepropertyradiusandtwoconstructors.Oneoftheconstructorshasnoargumentanditsetstheradiustozero;anotherconstructorsetstheradiusbyusingtheargumentprovided,orsetsradiustozerowhentheargumentislessthanzero.
⑶WriteaclassTestcontainingthemainmethodthatconvertseachcommand-lineargumenttodoublevalues,andcreateCircleobjectsaccordingtothedoublevaluesconverted.Exceptionhandlingshouldbeprovidedonconversingthecommand-linearguments.Ifanerroroccurred,printanerrormessageandcreatetheCircleusingthedefaultconstructor.Finally,calculateandoutputthesumareaofalltheCircles.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 软件 学院 面向 对象 程序设计 期末