java期末复习题.doc_第1页
java期末复习题.doc_第2页
java期末复习题.doc_第3页
java期末复习题.doc_第4页
java期末复习题.doc_第5页
已阅读5页,还剩75页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

此文档收集于网络,如有侵权,请联系网站删除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 Valueb. $_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 following 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.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?System.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.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 );Which of the following escape sequences 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.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.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 declaration.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 read 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 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. 127d. 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 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 != 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. Omitting 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 ObjectsSending 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. Left 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: 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.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 fully 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 That 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 methods. 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. 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 integers 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 detail.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 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 code 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. the 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 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 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. 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 between 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 statements 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 agree 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 occurs.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 static 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 return-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 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. LILO.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 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 Java 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. (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. charactersANS: 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 statement 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 the outputs of rolling a six-sided die? Suppose randomNumbers is a Random object.a. 1 + randomNumbers.nextInt( 6 );b. 1 + randomNumbers.nextInt( 2 ); c. 6 + randomNumbers.nextInt( 1 ); d. 3 + randomNumbers.nextInt( 3 ); ANS: a. 1 + randomNumbers.nextInt( 6 );Section 6.9.1 Generalized Scaling and Shifting of Random Numbers6.Which statement creates a random value from the sequence 2, 5, 8, 11 and 14. Suppose randomNumbers is a Random object.a. 2 + 5 * randomNumbers.nextInt( 3 );b. 3 + 2 * randomNumbers.nextInt( 5 );c. 5 + 3 * randomNumbers.nextInt( 2 );d. 2 + 3 * randomNumbers.nextInt( 5 );ANS: d. 2 + 3 * randomNumbers.nextInt( 5 );Section 6.9.2 Random-Number Repeatability for Testing and Debugging6.You can set a Random objects seed at any time during program execution by calling the objects _ methods.a. changeSeed.b. setSeed.c. resetSeed.d. updateSeed.ANS: b. setSeed.Section 6.10 Case Study: A Game of Chance (Introducing Enumerations)An enumeration is a special class that is introduced by the keyword _ and a type name.a. class.b. enum.c. enumeration.d. classEnum.ANS: b. enum.The identifiers in an enumeration _.a. must be unique.b. may be duplicated.c. must be lowercase letters and cannot contain numbers.d. must be uppercase letters and cannot contain numbers.ANS: a. must be unique.Section 6.11 Scope of DeclarationsIdentifiers in Java have _ and _ scopes?a. method, class.b. class, block.c. block, statement.d. statement, file.ANS: b. class, block.Which of the following statements describes block scope?a. It begins at the opening of the class declaration and terminates at the closing b. It limits label scope to only the method in which it is declared.c. It begins at the identifiers declaration and ends at the terminating right brace ().d. It is valid for one statement only.ANS: c. It begins at the identifiers declaration and ends at the terminating right brace ().Which of these statements best defines scope?a. Scope refers to the classes that have access to a variable.b. Scope determines whether a variables value can be altered.c. Scoping allows the programmer to use a class without using its fully qualified name.d. Scope is the portion of a program that can refer to an entity by its simple name.ANS: d. Scope is the portion of a program that can refer to an entity by its simple name.Section 6.12 Method OverloadingOverloaded methods always have the same _.a. method name.b. return type.c. number of parameters.d. order of the parameters.ANS: a. method name.An overloaded method is one thata. has a different name than another method, but the same parameters.b. has the same name as another method, but different parameters (by number, types or order of the types).c. has the same name and parameters as a method defined in another class.d. has

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论