1.
True or False: Void methods do not have a type.
Correct Answer
A. True
Explanation
Void methods do not have a type because the void keyword indicates that the method does not return any value. In programming, methods are typically defined with a return type to specify the type of value that the method will return. However, void is a special type that is used when a method does not return any value. Therefore, void methods do not have a type associated with them.
2.
A(n) ____ parameter is a variable declared in the method heading.
Correct Answer
formal
Explanation
A formal parameter is a variable declared in the method heading. This parameter is used to receive values from the caller when the method is called. It allows the method to accept inputs and perform operations on them within the method body. The formal parameter is defined in the method signature and its type and name must be specified.
3.
True or False: To use the method Math.sqrt(x) you must import the package java.lang.
Correct Answer
B. False
Explanation
The statement is false because the Math class is part of the java.lang package, which is automatically imported in every Java program. Therefore, you do not need to explicitly import the java.lang package to use the Math.sqrt(x) method.
4.
True or False: Void methods are always stand-alone statements.
Correct Answer
A. True
Explanation
Void methods are always stand-alone statements because they do not return any value and are used to perform a specific task without needing to return any result. They are typically used for actions or operations that do not require a return value, such as printing output or modifying variables. Since they do not produce a result that can be used by other parts of the program, they are considered stand-alone statements.
5.
An integer or string is a(n) ____ if it reads the same forwards and backwards.
Correct Answer
palindrome
Explanation
A palindrome is a word, phrase, number, or sequence of characters that reads the same forwards and backwards. This means that whether it is read from left to right or right to left, it remains unchanged. Palindromes can be made up of integers or strings and are commonly used in puzzles, word games, and coding challenges.
6.
____ variables are useful when you want to return more than one value from a method.
Correct Answer
Reference
Explanation
Reference variables are useful when you want to return more than one value from a method. By using a reference variable, you can pass the memory address of an object or data structure to the method, allowing it to modify the original object or data structure directly. This way, you can effectively return multiple values without having to create a new object or use complex data structures.
7.
True or False: It is possible to create several methods with the same name in a single class.
Correct Answer
A. True
Explanation
It is possible to create several methods with the same name in a single class. This is known as method overloading. Method overloading allows a class to have multiple methods with the same name but different parameters. The compiler determines which method to call based on the number, type, and order of the parameters passed to it. This allows for flexibility and reusability in coding, as different methods can perform similar actions but with different inputs.
8.
A(n)____ identifier is an identifier declared within a method or block that can be accessed only by code within that same method or block.
Correct Answer
local
Explanation
A local identifier is an identifier declared within a method or block that can be accessed only by code within that same method or block. This means that the variable or identifier is limited in scope and can only be used within the specific method or block in which it is declared. It cannot be accessed or used by any other methods or blocks outside of its scope.
9.
True or False: A method can be defined within the body of another method. This is known as nesting methods.
Correct Answer
B. False
Explanation
A method cannot be defined within the body of another method. This is not known as nesting methods. In programming, nesting methods refers to defining a method within another method, which is not allowed in most programming languages. Methods should be defined at the class level and can be called from other methods within the class.
10.
True or False: In the case of reference variables of the type String, we can use the assignment operator to allocate memory space to store a string and assign the string to a String variable.
Correct Answer
A. True
Explanation
In the case of reference variables of the type String, we can use the assignment operator to allocate memory space to store a string and assign the string to a String variable. This means that we can simply use the assignment operator (=) to create a new String object and assign it to a String variable. The assignment operator will allocate the necessary memory space to store the string and assign it to the variable.