Deck 5: Methods

Full screen (f)
exit full mode
Question
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.
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following is not a package in the Java API?

A) java.component
B) java.awt
C) javax.swing.event
D) java.lang
Question
When an object is concatenated with a String, ________.

A) a compilation error occurs
B) a runtime error occurs
C) the object's toString method is implicitly called to obtain the String representation of the object
D) the object's class name is concatenated with the String
Question
A well-designed method ________.

A) 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
Question
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);
Question
Which of the following statements is false?

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) None of the above.
Question
Which of the following methods is not in the Math class?

A) ceil
B) abs
C) parseInt
D) log
Question
Information is passed to a method in ________.

A) the method name
B) that method's return
C) the method body
D) the arguments to the method
Question
Which of the following can be an argument to a method?

A) Constants.
B) Variables.
C) Expressions.
D) All of the above.
Question
Method log takes the logarithm of its argument with respect to what base?

A) 10
B) e
C) 2
D) pi
Question
Stacks are known as ________ data structures.

A) FIFO.
B) FILO.
C) LIFO.
D) LILO.
Question
The parameter list in the method header and the arguments in the method call must agree in:

A) number
B) type
C) order
D) all of the above
Question
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.
Question
Which of the following promotions of primitive types is not allowed to occur?

A) char to int.
B) double to float.
C) int to double.
D) short to long.
Question
To declare a method as static, place the keyword static before ________ in the method's declaration.

A) the method modifier
B) the return type
C) the method name
D) the argument list
Question
Declaring main as static allows the JVM to invoke main ________.

A) without knowing the name of the class in which main is declared.
B) by creating an object of the class in which main is declared.
C) without creating an instance of the class in which main is declared.
D) None of the above.
Question
Which operator can be used in string concatenation?

A) *
B) +=
C) ++
D) =+
Question
The java.text package contains classes for manipulating all of the following items except ________.

A) classes
B) numbers
C) strings
D) characters
Question
Which of the following statements 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 method's body is a compilation error.
D) Forgetting to return a value from a method that should return a value is a compilation error.
Question
Math static method random generates a random double value in the range from 0.0

A) up to but not including 1.0
B) up to and including 1.0
C) up to and including 100.0
D) up to but not including 100.0
Question
Which statement below could be used to simulate the outputs of rolling a six-sided die? Suppose randomNumbers is a SecureRandom object.

A) 1 + randomNumbers.nextInt(6);
B) 1 + randomNumbers.nextInt(2);
C) 6 + randomNumbers.nextInt(1);
D) 3 + randomNumbers.nextInt(3);
Question
In a class containing methods with the same name, the methods are distinguished by ________.

A) Number of arguments
B) Types of arguments
C) Return type
D) (a) and (b)
E) (b) and (c)
Question
A set of named constants that start with the value 0 for the first constant and increment by 1 for each subsequent constant can be declared as a(n) ________.

A) class
B) enum
C) enumeration
D) None of the above.
Question
Java uses class ________ to represent colors using their RGB values.

A) Color
B) Colors
C) RGBColor
D) RGBColors
Question
Which statement below could be used to simulate the outputs of tossing a quarter to get heads or tails? Suppose randomNumbers is a SecureRandom object.

A) randomNumbers.nextInt(7);
B) randomNumbers.nextInt(2);
C) randomNumbers.nextInt(1);
D) randomNumbers.nextInt(25);
Question
Which of these statements best defines scope?

A) Scope refers to the classes that have access to a variable.
B) Scope determines whether a variable's value can be altered.
C) Scope is the portion of a program that can refer to an entity by its simple name.
D) Scope allows the programmer to use a class without using its fully qualified name.
Question
Method calls cannot be distinguished by ________.

A) method name
B) return type
C) parameter lists
D) method signature
Question
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 and B are overloaded; C and D are overloaded.
B) A and C are overloaded; B and D are overloaded.
C) A, B and C are overloaded.
D) All four methods are overloaded.
Question
Filled rectangles and filled circles are drawn using Graphics method ________ and ________.

A) fillRect, fillCircle
B) filledRect, filledCircle
C) fillRect, fillOval
D) filledRect, filledOval
Question
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.
Question
A Java class can have which of the following methods?
A) void foo(int a)
B) void foo(int a, int b)
C) void foo(double a)
D) void foo(double a, double b)
E) void foo(int b)

A) All of the above.
B) A, B, D, E.
C) A, B, C, D.
D) A, C, D, E.
Question
Which statement creates a random value from the sequence 2, 5, 8, 11 and 14. Suppose randomNumbers is a SecureRandom 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);
Question
Identifiers in Java have ________ and ________ scopes?

A) method, class.
B) class, block.
C) block, statement.
D) statement, file.
Question
An overloaded method is one that ________.

A) 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 the same name and parameters, but a different return type as another method
Question
Overloaded methods always have the same _________.

A) method name
B) return type
C) number of parameters
D) order of the parameters
Question
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 identifier's declaration and ends at the terminating right brace (}).
D) It is valid for one statement only.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/36
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 5: Methods
1
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.
B
2
Which of the following is not a package in the Java API?

A) java.component
B) java.awt
C) javax.swing.event
D) java.lang
A
3
When an object is concatenated with a String, ________.

A) a compilation error occurs
B) a runtime error occurs
C) the object's toString method is implicitly called to obtain the String representation of the object
D) the object's class name is concatenated with the String
C
4
A well-designed method ________.

A) 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
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
5
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);
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following statements is false?

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) None of the above.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following methods is not in the Math class?

A) ceil
B) abs
C) parseInt
D) log
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
8
Information is passed to a method in ________.

A) the method name
B) that method's return
C) the method body
D) the arguments to the method
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following can be an argument to a method?

A) Constants.
B) Variables.
C) Expressions.
D) All of the above.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
10
Method log takes the logarithm of its argument with respect to what base?

A) 10
B) e
C) 2
D) pi
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
11
Stacks are known as ________ data structures.

A) FIFO.
B) FILO.
C) LIFO.
D) LILO.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
12
The parameter list in the method header and the arguments in the method call must agree in:

A) number
B) type
C) order
D) all of the above
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
13
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.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following promotions of primitive types is not allowed to occur?

A) char to int.
B) double to float.
C) int to double.
D) short to long.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
15
To declare a method as static, place the keyword static before ________ in the method's declaration.

A) the method modifier
B) the return type
C) the method name
D) the argument list
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
16
Declaring main as static allows the JVM to invoke main ________.

A) without knowing the name of the class in which main is declared.
B) by creating an object of the class in which main is declared.
C) without creating an instance of the class in which main is declared.
D) None of the above.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
17
Which operator can be used in string concatenation?

A) *
B) +=
C) ++
D) =+
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
18
The java.text package contains classes for manipulating all of the following items except ________.

A) classes
B) numbers
C) strings
D) characters
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following statements 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 method's body is a compilation error.
D) Forgetting to return a value from a method that should return a value is a compilation error.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
20
Math static method random generates a random double value in the range from 0.0

A) up to but not including 1.0
B) up to and including 1.0
C) up to and including 100.0
D) up to but not including 100.0
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
21
Which statement below could be used to simulate the outputs of rolling a six-sided die? Suppose randomNumbers is a SecureRandom object.

A) 1 + randomNumbers.nextInt(6);
B) 1 + randomNumbers.nextInt(2);
C) 6 + randomNumbers.nextInt(1);
D) 3 + randomNumbers.nextInt(3);
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
22
In a class containing methods with the same name, the methods are distinguished by ________.

A) Number of arguments
B) Types of arguments
C) Return type
D) (a) and (b)
E) (b) and (c)
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
23
A set of named constants that start with the value 0 for the first constant and increment by 1 for each subsequent constant can be declared as a(n) ________.

A) class
B) enum
C) enumeration
D) None of the above.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
24
Java uses class ________ to represent colors using their RGB values.

A) Color
B) Colors
C) RGBColor
D) RGBColors
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
25
Which statement below could be used to simulate the outputs of tossing a quarter to get heads or tails? Suppose randomNumbers is a SecureRandom object.

A) randomNumbers.nextInt(7);
B) randomNumbers.nextInt(2);
C) randomNumbers.nextInt(1);
D) randomNumbers.nextInt(25);
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
26
Which of these statements best defines scope?

A) Scope refers to the classes that have access to a variable.
B) Scope determines whether a variable's value can be altered.
C) Scope is the portion of a program that can refer to an entity by its simple name.
D) Scope allows the programmer to use a class without using its fully qualified name.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
27
Method calls cannot be distinguished by ________.

A) method name
B) return type
C) parameter lists
D) method signature
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
28
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 and B are overloaded; C and D are overloaded.
B) A and C are overloaded; B and D are overloaded.
C) A, B and C are overloaded.
D) All four methods are overloaded.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
29
Filled rectangles and filled circles are drawn using Graphics method ________ and ________.

A) fillRect, fillCircle
B) filledRect, filledCircle
C) fillRect, fillOval
D) filledRect, filledOval
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
30
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.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
31
A Java class can have which of the following methods?
A) void foo(int a)
B) void foo(int a, int b)
C) void foo(double a)
D) void foo(double a, double b)
E) void foo(int b)

A) All of the above.
B) A, B, D, E.
C) A, B, C, D.
D) A, C, D, E.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
32
Which statement creates a random value from the sequence 2, 5, 8, 11 and 14. Suppose randomNumbers is a SecureRandom 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);
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
33
Identifiers in Java have ________ and ________ scopes?

A) method, class.
B) class, block.
C) block, statement.
D) statement, file.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
34
An overloaded method is one that ________.

A) 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 the same name and parameters, but a different return type as another method
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
35
Overloaded methods always have the same _________.

A) method name
B) return type
C) number of parameters
D) order of the parameters
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
36
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 identifier's declaration and ends at the terminating right brace (}).
D) It is valid for one statement only.
Unlock Deck
Unlock for access to all 36 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 36 flashcards in this deck.