Introduction To Java Programming Comprehensive Version 10th Edition Liang Test Bank Download
Introduction To Java Programming Comprehensive Version 10th Edition Liang Test Bank Download
txt
Introduction to Java Programming
Comprehensive Version 10th Edition Liang
Test Bank
Full download at link:
#
2. The signature of a method consists of _.
a. method name
b. method name and parameter list
c. return type, method name, and parameter list
d. parameter list
Key:b
#
3. All Java applications must have a method .
a. public static Main(String[] args)
b. public static Main(String args[])
c. public static void main(String[] args)
d. public void main(String[] args)
Page 1
chapter6.txt
e. public static main(String[] args)
Key:c
#
Sections 6.3 Calling a Method
4. Arguments to methods always appear within _.
a. brackets
b. parentheses
c. curly braces
d. quotation marks
Key:b
#
5. Does the return statement in the following method cause compile errors?
Page 2
chapter6.txt
b. No
Key:b It is rare, but sometimes useful to have a return statement for circumventing
the normal flow of control in a void method.
#
6. Does the method call in the following method cause compile errors?
#
7. Each time a method is invoked, the system stores parameters and local variables
in an area of memory, known as _, which stores elements in last-in first-out
fashion.
a. a heap
b. storage area
c. a stack
d. an array
key:c
#
Sections 6.4 void Method Example
8. Which of the following should be defined as a void method?
a. Write a method that prints integers from 1 to 100.
b. Write a method that returns a random integer from 1 to 100.
c. Write a method that checks whether current second is an integer from 1 to 100.
d. Write a method that converts an uppercase letter to lowercase.
key:a
#
8. You should fill in the blank in the following code with .
Page 3
chapter6.txt
if (score >= 90.0) {
System.out.println('A');
}
else if (score >= 80.0) {
System.out.println('B');
}
else if (score >= 70.0) {
System.out.println('C');
}
else if (score >= 60.0) {
System.out.println('D');
}
else {
System.out.println('F');
}
}
}
a. int
b. double
c. boolean
d. char
e. void
key:e
#
8. You should fill in the blank in the following code with .
Page 4
chapter6.txt
a. int
b. double
c. boolean
d. char
e. void
key:d
#
Sections 6.5 Passing Parameters by Values
9. When you invoke a method with a parameter, the value of the argument is passed to
the parameter. This is referred to as .
a. method invocation
b. pass by value
c. pass by reference
d. pass by name
key:b
#
10. Given the following method
#
11. Given the following method
int k = 2;
Page 5
chapter6.txt
nPrint("A message", k);
a. 0
b. 1
c. 2
d. 3
Key:c
#
Section 6.8 Overloading Methods
12. Analyze the following code:
#
13. Analyze the following code:
class Test {
public static void main(String[] args) {
System.out.println(xmethod(5));
}
Page 6
chapter6.txt
return n;
}
}
a. The program displays int followed by 5.
b. The program displays long followed by 5.
c. The program runs fine but displays things other than 5.
d. The program does not compile because the compiler cannot distinguish which
xmethod to invoke.
Key:b
#
14. Analyze the following code.
#
15. Analyze the following code.
Page 7
chapter6.txt
public class Test {
public static void main(String[] args) {
System.out.println(m(2));
}
#
Section 6.9 The Scope of Variables
16. A variable defined inside a method is referred to as .
a. a global variable
b. a method variable
c. a block variable
d. a local variable
key:d
#
17. What is k after the following block executes?
{
int k = 2;
nPrint("A message", k);
}
System.out.println(k);
a. 0
b. 1
c. 2
d. k is not defined outside the block. So, the program has a compile error
Key:d k is defined inside the block. Outside the block, k is not defined.
#
Section 6.10 Case Study: Generating Random Characters
25. (int)(Math.random() * (65535 + 1)) returns a random number .
a. between 1 and 65536
Page 8
chapter6.txt
b. between 1 and 65535
c. between 0 and 65535
d. between 0 and 65536
key:c
#
26. (int)('a' + Math.random() * ('z' - 'a' + 1)) returns a random number _.
a. between 0 and (int)'z'
b. between (int)'a' and (int)'z'
c. between 'a' and 'z'
d. between 'a' and 'y'
key:b
#
27. (char)('a' + Math.random() * ('z' - 'a' + 1)) returns a random character
_.
a. between 'a' and 'z'
b. between 'a' and 'y'
c. between 'b' and 'z'
d. between 'b' and 'y'
key:a
#
28. Which of the following is the best for generating random integer 0 or 1?
a. (int)Math.random()
b. (int)Math.random() + 1
c. (int)(Math.random() + 0.5)
d. (int)(Math.random() + 0.2)
e. (int)(Math.random() + 0.8)
key:c
#
Section 6.11 Method Abstraction and Stepwise Refinement
18. The client can use a method without knowing how it is implemented. The details
of the implementation are encapsulated in the method and hidden from the client who
invokes the method. This is known as .
a. information hiding
b. encapsulation
c. method hiding
d. simplifying method
key:ab
#
29. is to implement one method in the structure chart at a time from the
Page 9
chapter6.txt
d. Stepwise refinement
key:b
#
30. is a simple but incomplete version of a method.
a. A stub
b. A main method
c. A non-main method
d. A method developed using top-down approach
key:a
#
1. A method can be declared with no parameters.
a. true
b. false
Key:a
#
2. You can define two methods in the same class with the same name and
parameter list.
a. true
b. false
Key:b
#
3. A method can be defined inside a method in Java.
a. true
b. false
Key:b
#
4. The modifiers and return value type do not contribute toward distinguishing one
method from another, only the parameter list.
a. true
b. false
Key:a
#
5. A call for the method with a void return type is always a statement itself, but a
call for the method with a non-void return type can be treated as either a statement
or an expression.
a. true
b. false
Key:a
#
6. You must have a return statement in a non-void method.
a. true
Page 10
chapter6.txt
b. false
Key:a
#
8. You may have a return statement in a void method.
a. true
b. false
Key:a
#
9. The actual parameters of a method must match the formal parameters in type,
order, and number.
a. true
b. false
Key:a
#
11. You can redeclare the variable if it is declared in the method signature.
a. true
b. false
Key:b If a variable is declared as the formal parameter in the method, it's scope is
the entire method. Therefore, it cannot be redeclared inside the method.
#
12. The signature of a method consists of the method name, parameter list and
return type.
a. true
b. false
Key:b The signature of a method consists of the method name, parameter list, but
not the return type. A class cannot have the methods with identical signature.
#
1. A variable that is declared inside a method is called variable.
a. a static
b. an instance
c. a local
d. a global
e. a class
Key:c
#
2. Each Java class must contain a main method.
a. true
b. false
Key:b
#
4. Analyze the following code:
Page 11
chapter6.txt
class Test {
public static void main(String[] args) {
System.out.println(xMethod((double)5))
;
}
#
5. You may have a return statement in a void method.
a. true
b. false
Key:a
#
10. Which of the following is not an advantage of using methods.
a. Using methods makes programs run faster.
b. Using methods makes reusing code easier.
c. Using methods makes programs easier to read.
d. Using methods hides detailed implementation from the clients.
Key:a
#
15. If a method does not contain any parameters, you must invoke it with a pair of
empty parentheses.
a. true
b. false
Key:a
#
18. A method does not return a value.
a. void
b. non-void
Page 12
chapter6.txt
Key:a
#
19. Variables defined inside a method are called _.
a. parameters
b. arguments
c. local variables
d. global variables
Key:c
#
20. Variables defined in the method header are called .
a. parameters
b. arguments
c. local variables
d. global variables
Key:a
#
21. A variable or a value listed in a call to a method is called
a. a parameter
b. an argument
c. a local variable
d. a global variable
Key:b
#
22. Java allows you to declare methods with the same name in a class. This is called
_.
a. method duplication
b. method overriding
c. method overloading
d. method redeclaration
Key:c
#
23. A return statement without any value can be used in .
a. a non-void method
b. void method
Key:b
#
24. Methods can be declared in any order in a class.
a. true
b. false
Key:a
Page 13