JAVA Chapter 6

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Q3: Which statement below could be used to simulate the outputs of rolling a six-sided die? Suppose randomNumbers is a Random object. a. a. 1 + randomNumbers.nextInt( 6 ); b. b. 1 + randomNumbers.nextInt( 2 ); c. c. 6 + randomNumbers.nextInt( 1 ); d. d. 3 + randomNumbers.nextInt( 3 );

ANS: a. 1 + randomNumbers.nextInt( 6 );

Q1: Java uses class ________ to represent colors using their RGB values. a. a. Color. b. b. Colors. c. c. RGBColor. d. d. RGBColors.

ANS: a. Color.

Q2: Which statement is false? a. a. If a method does not return a value, the return-value-type in the method declaration can be omitted. b. b. Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error. c. c. Redeclaring a method parameter as a local variable in the method's body is a compilation error. d. 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.

Q3: The java.text package contains classes for manipulating all of the following items except a. a. classes b. b. numbers c. c. strings d. d. characters

ANS: a. classes

Q2: Which of the following is not a package in the Java API? a. a. java.component. b. b. java.awt. c. c. javax.swing.event. d. d. java.lang.

ANS: a. java.component.

Q1: Overloaded methods always have the same _________. a. a. method name. b. b. return type. c. c. number of parameters. d. d. order of the parameters.

ANS: a. method name.

Q2: The identifiers in an enumeration ________. a. a. must be unique. b. b. may be duplicated. c. c. must be lowercase letters and cannot contain numbers. d. d. must be uppercase letters and cannot contain numbers.

ANS: a. must be unique.

Q2: If more method calls occur than can have their activation records stored on the program execution stack, an error known as a ________ occurs. a. a. stack overflow. b. b. stack rewind. c. c. stack full. d. d. stack empty.

ANS: a. stack overflow.

Q1: Math static method random generates a random double value in the range from 0.0 a. a. up to but not including 1.0 b. b. up to and including 1.0 c. c. up to and including 100.0 d. d. up to but not including 100.0

ANS: a. up to but not including 1.0

Q4: Which operator can be used in string concatenation? a. a. *. b. b. +=. c. c. ++. d. d. =+.

ANS: b. +=.

Q1: Identifiers in Java have ________ and ________ scopes? a. a. method, class. b. b. class, block. c. c. block, statement. d. d. statement, file.

ANS: b. class, block.

3 Q5: Method log takes the logarithm of its argument with respect to what base? a. a. 10 b. b. e c. c. 2 d. d. pi

ANS: b. e

Q1: An enumeration is a special class that's introduced by the keyword ________ and a type name. a. a. class. b. b. enum. c. c. enumeration. d. d. classEnum.

ANS: b. enum.

Q2: An overloaded method is one that a. a. has a different name than another method, but the same parameters. b. b. has the same name as another method, but different parameters (by number, types or order of the types). c. c. has the same name and parameters as a method defined in another class. d. d. has the same name and parameters, but a different return type as another method.

ANS: b. has the same name as another method, but different parameters (by number, types or order of the types).

Q2: Which 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. a. randomNumbers.nextInt( 7 ); b. b. randomNumbers.nextInt( 2 ); c. c. randomNumbers.nextInt( 1 ); d. d. randomNumbers.nextInt( 25 );

ANS: b. randomNumbers.nextInt( 2 );

Q6: Method calls cannot be distinguished by ________. a. a. method name. b. b. return type. c. c. parameter lists. d. d. method signature.

ANS: b. return type.

Q1: You can set a Random object's seed at any time during program execution by calling the object's ________ methods. a. a. changeSeed. b. b. setSeed. c. c. resetSeed. d. d. updateSeed.

ANS: b. setSeed.

3 Q1: To declare a method as static, place the keyword static before ________ in the method's declaration. a. a. the method modifier. b. b. the return type. c. c. the method name. d. d. the argument list.

ANS: b. the return type.

Q2: 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. A method is called with its name and parentheses. b. b. x and y are parameters. c. c. Copies of x and y are passed to the method calculateValue. d. d. x and y are arguments.

ANS: b. x and y are paramters.

Q5: A Java class can have which of the following methods? A. A. void foo( int a ) B. B. void foo( int a, int b ) C. C. void foo( double a ) D. D. void foo( double a, double b ) E. E. void foo( int b ) a. a. All of the above. b. b. A, B, D, E. c. c. A, B, C, D. d. d. A, C, D, E.

ANS: c. A, B, C, D.

Q2: Which of the following statements describes block scope? a. a. It begins at the opening { of the class declaration and terminates at the closing } b. b. It limits label scope to only the method in which it is declared. c. c. It begins at the identifier's declaration and ends at the terminating right brace (}). d. d. It is valid for one statement only.

ANS: c. It begins at the identifier's declaration and ends at the terminating right brace (}).

Q1: Stacks are known as ________ data structures. a. a. FIFO. b. b. FILO. c. c. LIFO. d. d. LILO.

ANS: c. LIFO.

6.3 Q2: Which is a correct static method call of Math class method sqrt? a. a. sqrt( 900 );. b. b. math.sqrt( 900 );. c. c. Math.sqrt( 900 );. d. d. Math math = new Math(); math.sqrt( 900 );.

ANS: c. Math.sqrt( 900 );.

Q1: Which statement is not true. a. a. The Java API consists of packages. b. b. The Java API helps programmers avoid "reinventing the wheel." c. c. The Java API consists of import declarations. d. 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.)

Q2: Filled rectangles and filled circles are drawn using Graphics method ________ and ________. a. a. fillRect, fillCircle. b. b. filledRect, filledCircle. c. c. fillRect, fillOval, d. d. filledRect, filledOval.

ANS: c. fillRect, fillOval.

Q3: Which of the following methods is not in the Math class? a. a. ceil. b. b. abs. c. c. parseInt. d. d. log.

ANS: c. parseInt

Q7: Declaring main as ________ allows the JVM to invoke main without creating an instance of the class. a. a. public. b. b. void. c. c. static. d. d. final.

ANS: c. static.

Q5: When an object is concatenated with a String: a. a. a compilation error occurs. b. b. a runtime error occurs. c. c. the object's toString method is implicitly called to obtain the String representation of the object. d. d. the object's class name is used.

ANS: c. the object's toString method is implicitly called to obtain the String representation of the object.

Q1: Variables should be declared as fields only if a. a. they are local variables. b. b. they are used only within a method. c. c. they are required for use in more than one method or their values must be saved between calls to the class's methods. d. 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 class's methods.

Q4: Suppose method1 is declared as void method1 ( int a, float b ) Which of the following methods correctly overloads method1? a. a. void method2 ( int a, float b ). b. b. void method2 ( float a, int b ). c. c. void method1 ( float a, int b ). d. d. void method1 ( int b, float a ).

ANS: c. void method1 ( float a, int b ).

Q7: In a class containing methods with the same name, the methods are distinguished by: a. a. Number of arguments. b. b. Types of arguments. c. c. Return type. d. d. (a) and (b). e. e. (b) and (c).

ANS: d. (a) and (b).

Q1: Which statement creates a random value from the sequence 2, 5, 8, 11 and 14. Suppose randomNumbers is a Random object. a. a. 2 + 5 * randomNumbers.nextInt( 3 ); b. b. 3 + 2 * randomNumbers.nextInt( 5 ); c. c. 5 + 3 * randomNumbers.nextInt( 2 ); d. d. 2 + 3 * randomNumbers.nextInt( 5 );

ANS: d. 2 + 3 * randomNumbers.nextInt( 5 );

3 Q4: Which of the following can be an argument to a method? a. a. Constants. b. b. Variables. c. c. Expressions. d. d. All of the above.

ANS: d. All of the above.

Q1: A static method can ________. a. a. call only other static methods of the same class directly. b. b. manipulate only static fields in the same class directly. c. c. be called using the class name and a dot (.). d. d. All of the above.

ANS: d. All of the above.

Q3: Which of the following methods are overloaded with respect to one another? public int max ( int a, int b ) { ... } public double max ( double a, double b ) { ... } public int max ( int a, int b, int c ) { ... } public double max ( double a, double b, double c ) { ... } a. a. A and B are overloaded; C and D are overloaded. b. b. A and C are overloaded; B and D are overloaded. c. c. A, B and C are overloaded. d. d. All these four methods are overloaded.

ANS: d. All these four methods are overloaded.

Q2: Which of the following primitive types is never promoted to another type? a. a. double. b. b. byte. c. c. boolean. d. d. Both a and c.

ANS: d. Both a and c.

Q3: Which of these statements best defines scope? a. a. Scope refers to the classes that have access to a variable. b. b. Scope determines whether a variable's value can be altered. c. c. Scoping allows the programmer to use a class without using its fully qualified name. d. 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.

Q3: The parameter list in the method header and the arguments in the method call must agree in: a. a. number b. b. type c. c. order d. d. all of the above

ANS: d. all of the above

2 Q2: Programs designed for maintainability are constructed from small simple pieces or modules. Modules in Java are called: a. a. methods. b. b. classes. c. c. arguments. d. d. both methods and classes.

ANS: d. both methods and classes

Q1: Which of the following promotions of primitive types is not allowed to occur? a. a. char to int. b. b. int to double. c. c. short to long. d. d. double to float.

ANS: d. double to float.

Q6: Any field declared with keyword ________ is constant. a. a. static. b. b. const. c. c. constant. d. d. final.

ANS: d. final.

2 Q3: A well-designed method a. a. performs multiple unrelated tasks. b. b. repeats code found in other methods. c. c. contains thousands of lines of code. d. d. performs a single, well-defined task.

ANS: d. performs a single, well-defined task.

Q1: Information is passed to a method in: a. a. the method name. b. b. that method's return. c. c. the method body. d. d. the arguments to the method.

ANS: d. the arguments to the method.


संबंधित स्टडी सेट्स

PPT 28 - Intellectual Property Rights: Copyrights

View Set

Chapitre 2: QC *Nouvelle-France ~1608-1663-1754

View Set

Trigonometry - Solving Trig Equations

View Set

Chapter 8 Health Insurance Basics

View Set

CISCO Cybersecurity Essentials v1.1 - Final Quiz, Part A

View Set