Chapter 5 Book Quiz Flashcards
This type of method does not return a value.
a. null
b. void
c. empty
d. anonymous
b. void
Explanation: A void method is one that does not return a value. It simply performs an action but does not provide any output.
This appears at the beginning of a method definition.
a. semicolon
b. parentheses
c. body
d. header
d. header
Explanation: The method header is the part of the method definition that appears at the beginning and includes the method’s name, return type, and parameter list (if any).
The body of a method is enclosed in .
a. curly braces { }
b. square brackets []
c. parentheses ()
d. quotation marks “”
a. curly braces { }
Explanation: The body of a method is enclosed in curly braces { }, which contain the statements that define what the method does.
A method header can contain .
a. method modifiers
b. the method return type
c. the method name
d. a list of parameter declarations
e. all of these
f. none of these
e. all of these
Explanation: The method header includes all of the following: method modifiers (like public, static), the method return type (like void or int), the method name, and optionally a list of parameter declarations.
A value that is passed into a method when it is called is known as
a. parameter
b. argument
c. signal
d. return value
b. argument
Explanation: When you pass a value into a method, that value is called an argument. The method can then use this value by referring to it through the parameter.
A variable that receives a value that is passed into a method is known as a(n) .
a. parameter
b. argument
c. signal
d. return value
a. parameter
Explanation: A parameter is a variable declared in the method header that holds the value passed into the method when it is called
This javadoc tag is used to document a parameter variable.
a. @parameter
b. @param
c. @paramvar
d. @arg
b. @param
Explanation: The @param javadoc tag is used to document the parameters of a method, explaining what each parameter represents.
This statement causes a method to end and sends a value back to the statement that called the method.
a. end
b. send
c. exit
d. return
d. return
Explanation: The return statement is used to exit the method and optionally return a value to the caller.
This javadoc tag is used to document a method’s return value.
a. @methodreturn
b. @ret
c. @return
d. @returnval
c. @return
Explanation: The @return javadoc tag is used to describe the return value of a method in the documentation.
TRUE OR FALSE: You terminate a method header with a semicolon.
False
Explanation: A method header does not end with a semicolon. The method header ends with a pair of parentheses, and the body of the method is enclosed in curly braces.
TRUE OR False
Explanation: A method header does not end with a semicolon. The method header ends with a pair of parentheses, and the body of the method is enclosed in curly braces.
True
Explanation: Java will automatically perform widening conversions (like converting an int to a double) when needed, since the values fit without data loss.
TRUE OR FALSE: When passing an argument to a method, Java will automatically perform a narrowing conversion (convert the argument to a lower-ranking data type), if necessary.
False
Explanation: Java does not automatically perform narrowing conversions (like converting a double to an int). This requires explicit casting, and the compiler will throw an error if it’s attempted without it.
TRUE OR FALSE: A parameter variable’s scope is the entire program that contains the method in which the parameter is declared.
False
Explanation: The scope of a parameter variable is limited to the method in which it is declared. It is not accessible outside the method.
TRUE OR FALSE: When code in a method changes the value of a parameter, it also changes the value of the argument that was passed into the parameter.
False
Explanation: In Java, parameters are passed by value. If a method changes the value of a parameter, it does not affect the original argument passed to the method.
TRUE OR FALSE: When an object, such as a String, is passed as an argument, it is actually a reference to the object that is passed.
True
Explanation: When objects (like a String) are passed as arguments, what is actually passed is a reference to the object, not a copy of the object itself.