java期末复习题.docx
- 文档编号:10738466
- 上传时间:2023-05-27
- 格式:DOCX
- 页数:134
- 大小:63.77KB
java期末复习题.docx
《java期末复习题.docx》由会员分享,可在线阅读,更多相关《java期末复习题.docx(134页珍藏版)》请在冰点文库上搜索。
java期末复习题
End-of-linecommentsthatshouldbeignoredbythecompileraredenotedusing
a.Twoforwardslashes(//).
b.Threeforwardslashes(///).
c.Aslashandastar(/*).
d.Aslashandtwostarts(/**).
e.ANS:
a.Twoforwardslashes(//).
WhichofthefollowingisnotavalidJavaidentifier?
a.myValue
b.$_AAA1
c.width
d.m_x
ANS:
a.myValue(Identifiersmaynotcontainblanks).
WhichofthefollowingcannotcauseasyntaxerrortobereportedbytheJavacompiler?
a.Mismatched{}
b.Missing*/inacommentthatbeginswith/*
c.Missing;
d.Extrablanklines.
ANS:
d.Extrablanklines.
Whichofthefollowingisnotasyntaxerror?
a.System.out.println('Helloworld!
'):
b.System.out.println("Hello
world!
");
c.System.out.println("Helloworld!
");
d.System.out.println(Helloworld!
);
ANS:
c.System.out.println("Helloworld!
");
WhichcommandcompilestheJavasourcecodefileWelcome.java?
a.cdWelcome.java
b.javacWelcome.java
c.javaWelcome.java
d.compileWelcome.java
ANS:
b.javacWelcome.java
WhichcommandexecutestheJavaclassfileWelcome.class?
a.javacWelcome.class
b.javaWelcome.class
c.javaWelcome
d.runWelcome.class
ANS:
c.javaWelcome
Whichistheoutputofthefollowingstatements?
System.out.print("Hello");
System.out.println("World");
a.HelloWorld
b.HelloWorld
c.Hello
World
d.World
Hello
ANS:
a.HelloWorld
Whichofthefollowingcharactersistheescapecharacter?
a.*
b.\
c.\n
d."
ANS:
b.\
Whichofthefollowingstatementswillprintasinglelinecontaining"hellothere"?
a.System.out.println("hello");
System.out.println("there");
b.System.out.println("hello","there");
c.System.out.println("hello");
System.out.print("there");
d.System.out.print("hello");
System.out.println("there");
ANS:
d.System.out.print("hello");
System.out.println("there");
Whichofthefollowingescapesequencesrepresentscarriagereturn?
e.\n.
f.\r.
g.\cr.
h.\c.
ANS:
b.\r.
WhichofthefollowingstatementswoulddisplaythephaseJavaisfun?
a.System.out.println("helloisfun\rJava");
b.System.out.println('Javaisfun');
c.System.out.println("\"Javaisfun\"");
d.System.out.println(Javaisfun);
ANS:
a.System.out.println("helloisfun\rJava");
Whenmethodprintfrequiresmultiplearguments,theargumentsareseparatedwith________.
a.colons(:
).
b.semicolons(;).
c.commas(,).
d.periods(.).
ANS:
c.commas(,).
WhichofthefollowingstatementdisplaysHelloWorld?
a.System.out.printf("%2s","Hello""World");
b.System.out.printf("%s%s","Hello","World");
c.System.out.printf("%s%s","Hello,World");
d.System.out.printf("s%s%","Hello","World");
ANS:
b.System.out.printf("%s%s","Hello","World");
Allimportdeclarationsmustbeplaced
a.insidetheclassdeclaration’sbody.
b.beforetheclassdeclaration.
c.aftertheclassdeclaration.
d.alloftheabovewillwork.
ANS:
b.beforetheclassdeclaration.
Whichofthefollowingisavariabledeclarationstatement?
a.inttotal;
b.importjava.util.Scanner;
c.publicstaticvoidmain(Stringargs[])
d.//firststringenteredbyuser
ANS:
a.inttotal;
A(n)________enablesaprogramtoreaddatafromtheuser.
a.printf.
b.importdeclaration.
c.Scanner.
d.main.
ANS:
c.Scanner.
WhichofthefollowingisnotaJavaprimitivetype?
a.char
b.byte
c.real
d.double
ANS:
c.real
Theformatspecifier________isaplace-holderforanintvalue?
a.%a.
b.%d.
c.%int.
d.%s.
ANS:
b.%d.
Whichofthefollowingstatementsdoesnotalteramemorylocation?
a.inta;
b.number=12;
c.y=y+2;
d.width=Integer.parseInt(input);
ANS:
a.inta;
WhatisthevalueofresultafterthefollowingJavastatementsexecute?
inta,b,c,d,result;
a=4;
b=12;
c=37;
d=51;
result=d%a*c+a%b+a;
a.119
b.51
c.127
d.59
ANS:
a.119
Listthefollowingoperatorsintheorderthattheywillbeevaluated:
-,*,/,+,%.Assumethatiftwooperationshavethesameprecedence,theonelistedfirstwillbeevaluatedfirst.
a.+,-,/,*,%.
b.-,+,%,*,/.
c.-,*,%,+,/.
d.*,/,%,-,+.
ANS:
d.*,/,%,-,+.
Whichofthefollowingisnotanarithmeticoperator?
a.+
b.-
c..
d.%
ANS:
c..
WhatwillbeoutputafterthefollowingJavastatementshavebeenexecuted?
inta,b,c,d;
a=4;
b=12;
c=37;
d=51;
if(a
System.out.println("a
if(a>b)
System.out.println("a>b");
if(d<=c)
System.out.println("d<=c");
if(c!
=d)
System.out.println("c!
=d");
a.a
c!
=d
b.a
d<=c
c!
=d
c.a>b
c!
=d
d.a
c a! =b ANS: a.a c! =d Whichofthefollowingisnotacompilationerror? a.Neglectingtoinitializealocalvariableinamethodbeforeitisused. b.Placingasemicolonattheendofthefirstlineofanifstatement. c.Omittingtheleftandrightparenthesisfortheconditionofanifstatement. d.Allarecompilationerrors. ANS: b.Placingasemicolonattheendofthefirstlineofanifstatement. Eachofthefollowingisarelationalorequalityoperatorexcept: a.<= b.=! c.== d.> ANS: b.=! Chapter3IntroductiontoClassesandObjects Sendingamessagetoanobjectmeansthat: a.Youcallamethodoftheobject. b.Youaccessavariableoftheobject. c.Both(a)and(b). d.Neither(a)nor(b). ANS: a. Methodheaderscontainallofthefollowingexcept: e.Accessmodifier. f.Leftbrace. g.Nameofmethod. h.Returntype. ANS: b.Leftbrace. EveryJavaapplicationiscomposedofatleastone: a.localvariable b.instancevariable c.publicclassdeclaration d.importedclass ANSc.publicclassdeclaration Aclassinstancecreationexpressioncontains: a.Parentheses. b.Thenewkeyword. c.Thenameoftheclass. Alloftheabove. ANS: d.Alloftheabove. Callingamethodofanotherobjectrequireswhichitem? a.Thedotseparator. b.Openandclosebraces. c.Thenewkeyword. d.Noneoftheabove. ANSa.Thedotseparator. Whatisthenameofthevaluesthemethodcallpassestothemethodfortheparameters? a.Arguments. b.References. c.Objects. d.Values. ANS: a.Arguments. WhichofthefollowingisaScannermethod? a.nextLine. b.nextText. c.nextWord. d.readNext. ANS: a.nextLine. Multipleparametersareseparatedwithwhatsymbol? a.Dotseparator b.Comma. c.Parentheses. d.Braces. ANS: b.Commas. Whichofthefollowingisavalidfullyqualifiedname? a.Scanner. b.java.Scanner. c.util.Scanner. d.java.util.Scanner. ANS: d.java.util.Scanner. Section3.5InstanceVariables,setMethodsandgetMethods Attributesofaclassarealsoknownas: a.Constructors. b.Localvariables. c.Fields. d.Classes. ANS: c.Fields. GradeBookTestClassThatDemonstratesClassGradeBook WhatisthedefaultinitialvalueofaStringinstancevariable? a."" b."default" c.default d.null ANS: d.null setandgetMethods Whattypeofmethodsallowaclientofaclasstoassignvaluestoaprivateinstancevariable? a.Getmethods. b.Replacemethods. c.Assignmethods. d.Setmethods. ANS: d.Setmethods. Section3.6PrimitiveTypesvs.ReferenceTypes Whatisthedefaultvalueofareference? a.0. b."". c.null. d.default. ANS: c.null. Section3.7InitializingObjectswithConstructors Adefaultconstructorhashowmanyparameters? a.0. b.1. c.2. d.Variable. ANS: a.0. Section3.8Floating-PointNumbersandTypedouble WhichtwoJavaprimitivetypesstorefloating-pointnumbers? a.decimalandfloat. b.pointanddouble. c.floatanddouble. d.decimalandpoint. ANS: c.floatanddouble. Whatisthedifferencebetweenafloatandadouble? a.doublevariablesstoreintegersandfloatvariablesstorefloating-pointnumbers. b.doublevariablesstorenumberswithsmallermagnitudeandcoarserdetail. c.doublevariablesstorenumberswithlargermagnitudeandfinerdetail. d.Noneoftheabove. ANS: c.doublevariablesstorenumberswithlargermagnitudeandfinerdetail. Floating-PointNumberPrecisionandMemoryRequirements Howmanysignificantdigitsdoesadoublevariablehave? a.7. b.8. c.14. d.15. ANS: d.15. Informationispassedtoamethodin: a.themethodname. b.thatmethod'sreturn. c.themethodbody. d.theargumentstothemethod. ANS: d.theargumentstothemethod. Programsdesignedformaintainabilityareconstructedfromsmallsimplepiecesormodules.ModulesinJavaarecalled: a.methods. b.classes. c.arguments. d.bothmethodsandclasses. ANS: d.bothmethodsandclasses Awell-designedmethod a.performsmultipleunrelatedtasks. b.repeatscodefoundinothermethods. c.containsthousandsoflinesofcode. d.performsasingle,well-definedtask. ANS: d.performsasingle,well-definedtask. Section6.3staticMethods,staticFieldandClassMath Todeclareamethodasstatic,placethekeywordstaticbefore________inthemethod’sdeclaration. a.themethodmodifier. b.thereturntype. c.themethodname. d.theargumentlist. ANS: b.thereturntype. WhichisacorrectstaticmethodcallofMathclassmethodsqrt? a.sqrt(900);. b.math.sqrt(900);. c.Math.sqrt(900);. d.Mathmath=newMath();math.sqrt(900);. ANS: c.Math.sqrt(900);. WhichofthefollowingmethodsisnotintheMathclass? a.ceil. b.abs. c.parseInt. d.log. ANS: c.parseInt Whichofthefollowingcanbeanargumenttoamethod? a.Constants. b.Variables. c.Expressions. d.Alloftheabove. ANS: d.Alloftheabove. Methodlogtakesthelogarithmofitsargumentwithrespecttowhatbase? a.10 b.e c.2 d.pi ANS: b.e MathClassCons
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 期末 复习题