JAVA CHAPTER 6 EXAM QUESTIONS
WITH 100% COMPLETE SOLUTIONS
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 ); - Answer- ANS: d. 2 + 3 *
randomNumbers.nextInt( 5 );
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. - Answer- ANS: b. setSeed.
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. - Answer- ANS: b. enum.
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. - Answer- ANS: a. must
be unique.
Q1: Identifiers in Java have ________ and ________ scopes?
a. a. method, class.
b. b. class, block.
c. c. block, statement.
d. d. statement, file. - Answer- ANS: b. class, block.
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. - Answer- ANS: c. It begins at the identifier's
declaration and ends at the terminating right brace (}).
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. -
Answer- ANS: d. Scope is the portion of a program that can refer to an entity by its
simple name.
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. - Answer- ANS: a. method name.
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.
- Answer- ANS: b. has the same name as another method, but different parameters (by
number, types or order of the types).
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. - Answer- ANS: d. All these four methods
are overloaded.
Q4: Suppose method1 is declared as
void method1 ( int a, float b )
Which of the following methods correctly overloads method1?
WITH 100% COMPLETE SOLUTIONS
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 ); - Answer- ANS: d. 2 + 3 *
randomNumbers.nextInt( 5 );
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. - Answer- ANS: b. setSeed.
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. - Answer- ANS: b. enum.
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. - Answer- ANS: a. must
be unique.
Q1: Identifiers in Java have ________ and ________ scopes?
a. a. method, class.
b. b. class, block.
c. c. block, statement.
d. d. statement, file. - Answer- ANS: b. class, block.
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. - Answer- ANS: c. It begins at the identifier's
declaration and ends at the terminating right brace (}).
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. -
Answer- ANS: d. Scope is the portion of a program that can refer to an entity by its
simple name.
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. - Answer- ANS: a. method name.
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.
- Answer- ANS: b. has the same name as another method, but different parameters (by
number, types or order of the types).
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. - Answer- ANS: d. All these four methods
are overloaded.
Q4: Suppose method1 is declared as
void method1 ( int a, float b )
Which of the following methods correctly overloads method1?