java期末复习题.doc

上传人:仙人指路1688 文档编号:2386938 上传时间:2023-02-17 格式:DOC 页数:79 大小:717.50KB
返回 下载 相关 举报
java期末复习题.doc_第1页
第1页 / 共79页
java期末复习题.doc_第2页
第2页 / 共79页
java期末复习题.doc_第3页
第3页 / 共79页
java期末复习题.doc_第4页
第4页 / 共79页
java期末复习题.doc_第5页
第5页 / 共79页
点击查看更多>>
资源描述

《java期末复习题.doc》由会员分享,可在线阅读,更多相关《java期末复习题.doc(79页珍藏版)》请在三一办公上搜索。

1、End-of-line comments that should be ignored by the compiler are denoted usinga. Two forward slashes ( / ).b. Three forward slashes ( / ).c. A slash and a star ( /* ).d. A slash and two starts ( /* ).e. ANS: a. Two forward slashes ( / ).Which of the following is not a valid Java identifier?a. my Valu

2、eb. $_AAA1c. widthd. m_xANS: a. my Value (Identifiers may not contain blanks).Which of the following cannot cause a syntax error to be reported by the Java compiler?a. Mismatched b. Missing */ in a comment that begins with /*c. Missing ;d. Extra blank lines.ANS: d. Extra blank lines.Which of the fol

3、lowing is not a syntax error?a. System.out.println( Hello world! ):b. System.out.println( Hello world! );c. System.out.println( Hello world! );d. System.out.println( Hello world! );ANS: c. System.out.println( Hello world! );Which command compiles the Java source code file Welcome.java?a. cd Welcome.

4、javab. javac Welcome.javac. java Welcome.javad. compile Welcome.javaANS: b. javac Welcome.javaWhich command executes the Java class file Welcome.class?a. javac Welcome.classb. java Welcome.classc. java Welcomed. run Welcome.classANS: c. java WelcomeWhich is the output of the following statements?Sys

5、tem.out.print( Hello );System.out.println( World );a. Hello Worldb. HelloWorldc. HelloWorldd. WorldHelloANS: a. Hello WorldWhich of the following characters is the escape character?a. *b. c. nd. ANS: b. Which of the following statements will print a single line containing hello there?a. System.out.p

6、rintln( 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 );Which of the following escape seque

7、nces represents carriage return?e. n.f. r.g. cr.h. c.ANS: b. r.Which of the following statements would display the phase Java is fun?a. System.out.println( hellois funrJava );b. System.out.println( Java is fun );c. System.out.println( Java is fun );d. System.out.println( Java is fun );ANS: a. System

8、.out.println( hellois funrJava );When method printf requires multiple arguments, the arguments are separated with _.a. colons (:).b. semicolons (;).c. commas (,).d. periods (.).ANS: c. commas (,).Which of the following statement displays Hello World?a. System.out.printf( %2s, Hello World );b. System

9、.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 );All import declarations must be placeda. inside the class declarations body.b. before the class declaration.c. after the class de

10、claration.d. all of the above will work.ANS: b. before the class declaration.Which of the following is a variable declaration statement?a. int total;b. import java.util.Scanner;c. public static void main( String args )d. / first string entered by userANS: a. int total;A(n) _ enables a program to rea

11、d data from the user.a. printf.b. import declaration.c. Scanner.d. main.ANS: c. Scanner.Which of the following is not a Java primitive type?a. charb. bytec. reald. doubleANS: c. realThe format specifier _ is a place-holder for an int value?a. %a.b. %d.c. %int.d. %s.ANS: b. %d.Which of the following

12、statements does not alter a memory location?a. int a;b. number = 12;c. y = y + 2;d. width = Integer.parseInt(input);ANS: a. int a;What is the value of result after the following Java statements execute?int a, b, c, d, result;a = 4;b = 12;c = 37;d = 51;result = d % a * c + a % b + a; a. 119b. 51c. 12

13、7d. 59ANS: a. 119List the following operators in the order that they will be evaluated: -, *, /, +, %. Assume that if two operations have the same precedence, the one listed first will be evaluated first.a. +, -, /, *, %.b. -, +, %, *, /.c. -, *, %, +, /.d. *, /, %, -, +.ANS: d. *, /, %, -, +.Which

14、of the following is not an arithmetic operator?a. +b. -c. .d. %ANS: c. .What will be output after the following Java statements have been executed?int a, b, c, d;a = 4;b = 12;c = 37;d = 51;if ( a b ) System.out.println( a b ) System.out.println( a b );if ( d = c ) System.out.println( d = c );if ( c

15、!= d ) System.out.println( c != d ); a. a bc != db. a bd b c != dd. a bc d a != bANS: a. a b c != dWhich of the following is not a compilation error?a. Neglecting to initialize a local variable in a method before it is used.b. Placing a semicolon at the end of the first line of an if statement.c. Om

16、itting the left and right parenthesis for the condition of an if statement.d. All are compilation errors.ANS: b. Placing a semicolon at the end of the first line of an if statement.Each of the following is a relational or equality operator except:a. ANS: b. =!Chapter 3 Introduction to Classes and Ob

17、jectsSending a message to an object means that:a. You call a method of the object.b. You access a variable of the object.c. Both (a) and (b).d. Neither (a) nor (b).ANS: a. Method headers contain all of the following except: e. Access modifier.f. Left brace.g. Name of method.h. Return type.ANS: b. Le

18、ft brace.Every Java application is composed of at least one:a. local variableb. instance variablec. public class declarationd. imported classANS c. public class declarationA class instance creation expression contains: a. Parentheses.b. The new keyword.c. The name of the class.All of the above.ANS:

19、d. All of the above.Calling a method of another object requires which item?a. The dot separator.b. Open and close braces.c. The new keyword.d. None of the above.ANS a. The dot separator.What is the name of the values the method call passes to the method for the parameters?a. Arguments.b. References.

20、c. Objects.d. Values.ANS: a. Arguments.Which of the following is a Scanner method?a. nextLine.b. nextText.c. nextWord.d. readNext.ANS: a. nextLine.Multiple parameters are separated with what symbol?a. Dot separatorb. Comma.c. Parentheses.d. Braces.ANS: b. Commas.Which of the following is a valid ful

21、ly qualified name?a. Scanner.b. java.Scanner.c. util.Scanner.d. java.util.Scanner.ANS: d. java.util.Scanner.Section 3.5 Instance Variables, set Methods and get MethodsAttributes of a class are also known as:a. Constructors.b. Local variables.c. Fields.d. Classes.ANS: c. Fields.GradeBookTest Class Th

22、at Demonstrates Class GradeBookWhat is the default initial value of a String instance variable?a. b. defaultc. defaultd. nullANS: d. nullset and get MethodsWhat type of methods allow a client of a class to assign values to a private instance variable?a. Get methods. b. Replace methods. c. Assign met

23、hods. d. Set methods. ANS: d. Set methods.Section 3.6 Primitive Types vs. Reference TypesWhat is the default value of a reference?a. 0.b. .c. null.d. default.ANS: c. null.Section 3.7 Initializing Objects with ConstructorsA default constructor has how many parameters?a. 0.b. 1.c. 2.d. Variable.ANS: a

24、. 0.Section 3.8 Floating-Point Numbers and Type doubleWhich two Java primitive types store floating-point numbers?a. decimal and float.b. point and double.c. float and double.d. decimal and point.ANS: c. float and double.What is the difference between a float and a double?a. double variables store i

25、ntegers and float variables store floating-point numbers.b. double variables store numbers with smaller magnitude and coarser detail.c. double variables store numbers with larger magnitude and finer detail.d. None of the above.ANS: c. double variables store numbers with larger magnitude and finer de

26、tail.Floating-Point Number Precision and Memory RequirementsHow many significant digits does a double variable have?a. 7.b. 8.c. 14.d. 15.ANS: d. 15.Information is passed to a method in:a. the method name.b. that methods return.c. the method body.d. the arguments to the method.ANS: d. the arguments

27、to the method.Programs designed for maintainability are constructed from small simple pieces or modules. Modules in Java are called:a. methods.b. classes.c. arguments.d. both methods and classes.ANS: d. both methods and classesA well-designed methoda. performs multiple unrelated tasks.b. repeats cod

28、e found in other methods.c. contains thousands of lines of code.d. performs a single, well-defined task.ANS: d. performs a single, well-defined task.Section 6.3 static Methods, static Field and Class MathTo declare a method as static, place the keyword static before _ in the methods declaration.a. t

29、he method modifier.b. the return type.c. the method name.d. the argument list.ANS: b. the return type.Which is a correct static method call of Math class method sqrt?a. sqrt( 900 );.b. math.sqrt( 900 );.c. Math.sqrt( 900 );.d. Math math = new Math(); math.sqrt( 900 );.ANS: c. Math.sqrt( 900 );.Which

30、 of the following methods is not in the Math class?a. ceil.b. abs.c. parseInt.d. log.ANS: c. parseIntWhich of the following can be an argument to a method?a. Constants.b. Variables.c. Expressions.d. All of the above.ANS: d. All of the above.Method log takes the logarithm of its argument with respect

31、 to what base?a. 10b. ec. 2d. piANS: b. eMath Class Constants PI and EAny field declared with keyword _ is constant.a. static.b. const.c. constant.d. final.ANS: d. final.Why Is Method main Declared static?Declaring main as _ allows the JVM to invoke main without creating an instance of the class.a.

32、public.b. void.c. static.d. final.ANS: c. static.Section 6.4 Declaring Methods with Multiple ParametersVariables should be declared as fields only ifa. they are local variables.b. they are used only within a method.c. they are required for use in more than one method or their values must be saved be

33、tween calls to the classs methods.d. they are arguments.ANS: c. they are required for use in more than one method or their values must be saved between calls to the classs methods.Consider the following Java statements:int x = 9;double y = 5.3;result = calculateValue( x, y );Which of the following s

34、tatements is false?a. A method is called with its name and parentheses.b. x and y are parameters.c. Copies of x and y are passed to the method calculateValue().d. x and y are arguments.ANS: b. x and y are paramters.The parameter list in the method header and the arguments in the method call must agr

35、ee in:a. numberb. typec. orderd. all of the aboveANS: d. all of the aboveAssembling Strings with String ConcatenationWhich operator can be used in string concatenation?a. *.b. +=.c. +.d. =+.ANS: b. +=.When an object is concatenated with a String:a. a compilation error occurs.b. a runtime error occur

36、s.c. the objects toString method is implicitly called to obtain the String representation of the object.d. the objects class name is used.ANS: c. the objects toString method is implicitly called to obtain the String representation of the object.Section 6.5 Notes on Declaring and Using MethodsA stati

37、c method can _.a. call only other static methods of the same class directly.b. manipulate only static fields in the same class directly.c. be called using the class name and a dot (.).d. All of the above.ANS: d. All of the above.Which statement is false?a. If a method does not return a value, the re

38、turn-value-type in the method declaration can be omitted.b. Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error.c. Redeclaring a method parameter as a local variable in the methods body is a compilation error.d. Forgetting to return

39、a value from a method that should return a value is a compilation error.ANS: a. If a method does not return a value, the return-value-type in the method declaration can be omitted.Section 6.6 Method Call Stack and Activation RecordsStacks are known as _ data structures.a. FIFO.b. FILO.c. LIFO.d. LIL

40、O.ANS: c. LIFO.If more method calls occur than can have their activation records stored on the program execution stack, an error known as a _ occurs.a. stack overflow.b. stack rewind.c. stack full.d. stack empty.ANS: a. stack overflow.Section 6.7 Argument Promotion and CastingWhich of the following

41、promotions of primitive types is not allowed to occur?a. char to int.b. int to double.c. short to long.d. double to float.ANS: d. double to float.Which of the following primitive types is never promoted to another type?a. double.b. byte.c. boolean.d. Both a and c.ANS: d. Both a and c.Section 6.8 Jav

42、a API PackagesWhich statement is not true.a. The Java API consists of packages.b. The Java API helps programmers avoid reinventing the wheel.c. The Java API consists of import declarations.d. The class javax.swing.JApplet is part of the Java API.ANS: c. The Java API consists of import declarations.

43、(The Java API is built from packages.)Which of the following is not a package in the Java API?a. ponent.b. java.awt.c. javax.swing.event.d. java.lang.ANS: a. ponent.a. The java.text package contains classes for manipulating all of the following items exceptb. classesc. numbersd. stringse. characters

44、ANS: a. classesSection 6.9 Case Study: Random-Number GenerationMath static method random generates a random double value in the range from 0.0a. up to but not including 1.0b. up to and including 1.0c. up to and including 100.0d. up to but not including 100.0ANS: a. up to but not including 1.0Which s

45、tatement below could be used to simulate the outputs of tossing a quarter to get heads or tails? Suppose randomNumbers is a Random object.a. randomNumbers.nextInt( 7 );b. randomNumbers.nextInt( 2 ); c. randomNumbers.nextInt( 1 ); d. randomNumbers.nextInt( 25 ); ANS: b. randomNumbers.nextInt( 2 );Rolling a Six-Sided DieWhich statement below could be used to simulate th

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号