Deck 7: User-Defined Methods

Full screen (f)
exit full mode
Question
Void methods must have at least one parameter.
Use Space or
up arrow
down arrow
to flip the card.
Question
An identifier can be declared anywhere including within a class, and outside of every method definition (and every block).
Question
Just like the nesting of loops, Java allows the nesting of methods.
Question
In order to use the method isUpperCase of the class Character, the package java.lang must be explicitly imported.
Question
A local identifier is an identifier that is declared within a method or block and that is visible only within that method or block.
Question
Void methods use the return statement to return the value 0.
Question
The class Math is contained in the package java.math.
Question
If a formal parameter is a variable of a primitive data type, then after copying the value of the actual parameter, there is no connection between the formal and actual parameter.
Question
When a program executes, the first statement to execute is always the first statement in the main method.
Question
Suppose that the following statement is included in a program. import static java.lang.Math.*; After this statement, a static method of the class Math can be called using just the method name.
Question
You can use the class String to pass strings as parameters to a method and change the actual parameter.
Question
Methods are also called modules.
Question
An actual parameter is a variable or expression listed in a method call.
Question
Strings assigned to StringBuffer variables can be altered.
Question
Reference variables as parameters allow you to return more than one value from a method.
Question
The return statement must be the last line of the method.
Question
The word static is a return type in Java.
Question
To use a predefined method, you must know the code in the body of the method.
Question
In Java, return is a reserved word.
Question
Actual and formal parameters have a one-to-one correspondence.
Question
Java allows the programmer to declare a variable in the initialization statement of the for statement.
Question
Based on the code in the accompanying figure, what would be the output of the following statement? System.out.println(secret(5, 7.0));

A) 5.0
B) 7.0
C) 2.0
D) 35.0
Question
Which of the following is NOT part of the heading of the method in the accompanying figure?

A) public
B) static
C) secret(int first, double second)
D) double temp;
Question
Based on the code in the accompanying figure, what would be the output of the following statement? System.out.println(mystery(8, mystery(2, 1));

A) 5
B) 7
C) 11
D) 13
Question
How can a method send a primitive value back to the caller?

A) It cannot send primitive values back to the caller
B) By using the return statement
C) By assigning the value to one of its parameters
D) It can call its caller with the value
Question
What is an actual parameter?

A) The value passed into a method by a method call
B) The value returned by a method
C) The type of the method
D) A variable declared in the method heading
Question
What is the return type of the method in the accompanying figure?

A) public
C) void
B) int
D) double
Question
Which of the following statements about the method heading in the accompanying figure is NOT true?

A) The method has two parameters.
B) The method cannot be used outside the class.
C) methodHeading is an identifier giving a name to this specific method.
D) It is a value-returning method of type char.
Question
What is the name of the method in the accompanying figure?

A) first
C) secret
B) second
D) double
Question
Which of the following is a valid call to the method in the accompanying figure?

A) secret(5, 4.8);
B) secret(int 5, double 4.8);
C) secret(int x, double y);
D) public static int secret(5, 4.8);
Question
Which of the following is NOT true about return statements?

A) A value-returning method returns its value via the return statement.
B) return statements can be used in void methods to return values.
C) A method can have more than one return statement.
D) Whenever a return statement executes in a method, the remaining statements are skipped and the method exits.
Question
Two methods are said to have different formal parameter lists if both methods have a different number of formal parameters, or if the data types of the formal parameters are the same.
Question
Based on the method heading in the accompanying figure, what is the return type of the value returned?

A) static
C) int
B) char
D) num
Question
The signature of a method consists of only its formal parameter list.
Question
All the methods defined in a class must have different names.
Question
Which modifier is used to specify that a method cannot be used outside a class?

A) public
C) static
B) abstract
D) private
Question
Formal parameters of primitive data types provide ____ between actual parameters and formal parameters.

A) a one-way link
C) a three-way link
B) a two-way link
D) no link
Question
Within a method, an identifier used to name a variable in the outer block of the method can be used to name any other variable in an inner block of the method.
Question
Which of the following statements is NOT true?

A) Reference variables do not directly contain the data.
B) Reference variables contain the address of the memory space where the data is stored.
C) The operator new must always be used to allocate space of a specific type, regardless of the type.
D) A String variable is actually a reference variable of the type String.
Question
Based on the code in the accompanying figure, what would be the output of the following statement? System.out.println(mystery(8,7));

A) 1
B) 7
C) 8
D) 15
Question
Given the method heading in the accompanying figure, which of the following does NOT demonstrate method overloading?

A) int larger(int x, int y, int z)
B) int larger(char x)
C) int max(int x, int y)
D) double larger(double x, double y)
Question
Which of the following is an example of a local identifier in the example seen in the accompanying figure?

A) intRate (Line 3)
C) salary (Line 17)
B) name (Line 4)
D) t (line 15)
Question
Which of the following identifiers seen in the accompanying figure is NOT visible in method funcOne?

A) intRate (Line 3)
C) salary (Line 17)
B) u (Line 24)
D) first (Line 13)
Question
Which of the following identifiers seen in the accompanying figure is visible in block one?

A) name (Line 4)
C) local variables of main
B) t (Line 9)
D) x (Line 13)
Question
The program that tests a method is called a ____ program.

A) tester
C) stub
B) driver
D) debugging
Question
Which of the following identifiers seen in the accompanying figure is visible in method first?

A) intRate (Line 3)
C) u (Line 24)
B) local variables of method funcOne
D) first (Line 8)
Question
Which of the following statements about strings is NOT true?

A) When you use the assignment operator to assign a string to a String variable, the computer allocates memory space large enough to store the string.
B) When a string is assigned to a String variable, the string cannot be changed.
C) The class String contains many methods that allow you to change an existing string.
D) A String variable is actually a reference variable.
Question
The technique to solve a problem by subdividing into smaller problems is known as divide-and- conquer and ____ design approach.

A) top-down
C) leveled
B) bottom-up
D) driver and stub
Question
Given the method heading in the accompanying figure, which of the following would be an incorrect demonstration of method overloading?

A) int larger(int a, int b)
B) int larger(int x, int y, int z)
C) double larger(double x, double y)
D) char larger(char x, char y, char z)
Question
Which of the following identifiers seen in the accompanying figure is visible in main?

A) t (Line 5)
C) local variables of method funcOne
B) salary (Line 17)
D) All identifiers are visible in main.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 7: User-Defined Methods
1
Void methods must have at least one parameter.
False
2
An identifier can be declared anywhere including within a class, and outside of every method definition (and every block).
True
3
Just like the nesting of loops, Java allows the nesting of methods.
False
4
In order to use the method isUpperCase of the class Character, the package java.lang must be explicitly imported.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
A local identifier is an identifier that is declared within a method or block and that is visible only within that method or block.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
Void methods use the return statement to return the value 0.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
The class Math is contained in the package java.math.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
If a formal parameter is a variable of a primitive data type, then after copying the value of the actual parameter, there is no connection between the formal and actual parameter.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
When a program executes, the first statement to execute is always the first statement in the main method.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
Suppose that the following statement is included in a program. import static java.lang.Math.*; After this statement, a static method of the class Math can be called using just the method name.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
You can use the class String to pass strings as parameters to a method and change the actual parameter.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
Methods are also called modules.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
An actual parameter is a variable or expression listed in a method call.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Strings assigned to StringBuffer variables can be altered.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
Reference variables as parameters allow you to return more than one value from a method.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
The return statement must be the last line of the method.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
The word static is a return type in Java.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
To use a predefined method, you must know the code in the body of the method.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
In Java, return is a reserved word.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
Actual and formal parameters have a one-to-one correspondence.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
Java allows the programmer to declare a variable in the initialization statement of the for statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Based on the code in the accompanying figure, what would be the output of the following statement? System.out.println(secret(5, 7.0));

A) 5.0
B) 7.0
C) 2.0
D) 35.0
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following is NOT part of the heading of the method in the accompanying figure?

A) public
B) static
C) secret(int first, double second)
D) double temp;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
Based on the code in the accompanying figure, what would be the output of the following statement? System.out.println(mystery(8, mystery(2, 1));

A) 5
B) 7
C) 11
D) 13
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
How can a method send a primitive value back to the caller?

A) It cannot send primitive values back to the caller
B) By using the return statement
C) By assigning the value to one of its parameters
D) It can call its caller with the value
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
What is an actual parameter?

A) The value passed into a method by a method call
B) The value returned by a method
C) The type of the method
D) A variable declared in the method heading
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
What is the return type of the method in the accompanying figure?

A) public
C) void
B) int
D) double
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following statements about the method heading in the accompanying figure is NOT true?

A) The method has two parameters.
B) The method cannot be used outside the class.
C) methodHeading is an identifier giving a name to this specific method.
D) It is a value-returning method of type char.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
What is the name of the method in the accompanying figure?

A) first
C) secret
B) second
D) double
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following is a valid call to the method in the accompanying figure?

A) secret(5, 4.8);
B) secret(int 5, double 4.8);
C) secret(int x, double y);
D) public static int secret(5, 4.8);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following is NOT true about return statements?

A) A value-returning method returns its value via the return statement.
B) return statements can be used in void methods to return values.
C) A method can have more than one return statement.
D) Whenever a return statement executes in a method, the remaining statements are skipped and the method exits.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
Two methods are said to have different formal parameter lists if both methods have a different number of formal parameters, or if the data types of the formal parameters are the same.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
Based on the method heading in the accompanying figure, what is the return type of the value returned?

A) static
C) int
B) char
D) num
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
The signature of a method consists of only its formal parameter list.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
All the methods defined in a class must have different names.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Which modifier is used to specify that a method cannot be used outside a class?

A) public
C) static
B) abstract
D) private
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
Formal parameters of primitive data types provide ____ between actual parameters and formal parameters.

A) a one-way link
C) a three-way link
B) a two-way link
D) no link
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
Within a method, an identifier used to name a variable in the outer block of the method can be used to name any other variable in an inner block of the method.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following statements is NOT true?

A) Reference variables do not directly contain the data.
B) Reference variables contain the address of the memory space where the data is stored.
C) The operator new must always be used to allocate space of a specific type, regardless of the type.
D) A String variable is actually a reference variable of the type String.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Based on the code in the accompanying figure, what would be the output of the following statement? System.out.println(mystery(8,7));

A) 1
B) 7
C) 8
D) 15
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
Given the method heading in the accompanying figure, which of the following does NOT demonstrate method overloading?

A) int larger(int x, int y, int z)
B) int larger(char x)
C) int max(int x, int y)
D) double larger(double x, double y)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
Which of the following is an example of a local identifier in the example seen in the accompanying figure?

A) intRate (Line 3)
C) salary (Line 17)
B) name (Line 4)
D) t (line 15)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following identifiers seen in the accompanying figure is NOT visible in method funcOne?

A) intRate (Line 3)
C) salary (Line 17)
B) u (Line 24)
D) first (Line 13)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
Which of the following identifiers seen in the accompanying figure is visible in block one?

A) name (Line 4)
C) local variables of main
B) t (Line 9)
D) x (Line 13)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
The program that tests a method is called a ____ program.

A) tester
C) stub
B) driver
D) debugging
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following identifiers seen in the accompanying figure is visible in method first?

A) intRate (Line 3)
C) u (Line 24)
B) local variables of method funcOne
D) first (Line 8)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
Which of the following statements about strings is NOT true?

A) When you use the assignment operator to assign a string to a String variable, the computer allocates memory space large enough to store the string.
B) When a string is assigned to a String variable, the string cannot be changed.
C) The class String contains many methods that allow you to change an existing string.
D) A String variable is actually a reference variable.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
The technique to solve a problem by subdividing into smaller problems is known as divide-and- conquer and ____ design approach.

A) top-down
C) leveled
B) bottom-up
D) driver and stub
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
Given the method heading in the accompanying figure, which of the following would be an incorrect demonstration of method overloading?

A) int larger(int a, int b)
B) int larger(int x, int y, int z)
C) double larger(double x, double y)
D) char larger(char x, char y, char z)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Which of the following identifiers seen in the accompanying figure is visible in main?

A) t (Line 5)
C) local variables of method funcOne
B) salary (Line 17)
D) All identifiers are visible in main.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.