Name: 
 

JavaChapter2



Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 1. 

1. A set of values and the operations that can be carried out with those values are called _______.
a.
literals
c.
values
b.
numbers
d.
types
 

 2. 

What is the name of the type that denotes floating-point numbers that can have fractional parts?
a.
double
c.
int
b.
floating point
d.
integer
 

 3. 

What is the name of the type that denotes whole numbers?
a.
double
c.
whole
b.
int
d.
integer
 

 4. 

Which of the following declares a variable that will store a welcome message?
a.
String welcome;
c.
Char welcome;
b.
double welcome;
d.
int welcome;
 

 5. 

Which term is used to describe the name of a variable, method, or class?
a.
type
c.
identifier
b.
literal
d.
label
 

 6. 

By convention, classes begin with a(n) _____________.
a.
lowercase letter
c.
digit
b.
dollar sign
d.
uppercase letter
 

 7. 

Which statement declares and stores an integer value in a variable?
a.
count = 5;
c.
integer count = 5;
b.
int count = 5;
d.
String count = 5;
 

 8. 

Assume that the variable count has been declared as type int. Which statement adds 10 to count?
a.
count = 10;
c.
count = count + 10;
b.
count == count + 10;
d.
count + 10;
 

 9. 

Which of the following code fragments will cause an error?
a.
String greeting = "Hello, Dave!";
c.
int luckyNumber;  System.out.println(luckyNumber);
b.
String greeting = "Hello, World!";  int n = greeting.length();
d.
PrintStream printer = System.out;
 

 10. 

What is an object?
a.
A sequence of instructions.
c.
An entity in your program that is manipulated by calling methods.
b.
Any value stored in a variable.
d.
Any input to a method.
 

 11. 

What is the type of an object?
a.
variable
c.
method
b.
reference
d.
class
 

 12. 

Which of the following statements about methods is correct?
a.
A method is a sequence of instructions that could access the data of an object
c.
A method can be called on any object in any class.
b.
A method name is unique across the entire program.
d.
Methods are stored in variables.
 

 13. 

Which is not a method of the String class?
a.
length
c.
toLowerCase
b.
toUpperCase
d.
println
 

 14. 

Which method call represents the invocation of a method that does not have explicit parameters?
a.
greeting.replace("Hello", "Welcome");
c.
greeting.length()
b.
greeting.length
d.
System.out.println(greeting);
 

 15. 

The output of a method is called its __________ value.
a.
implicit
c.
parameter
b.
explicit
d.
return
 

 16. 

Which of the following method calls illustrates the return value of a method as a parameter?
a.
greeting.length();
c.
System.out.println(length.greeting());
b.
greeting.println("Hello");
d.
System.out.println(greeting.length());
 

 17. 

What terminology describes a method that returns information about its implicit parameter and does not change the parameter's internal data?
a.
mutator
c.
void
b.
accessor
d.
public
 

 18. 

Which of the following is a mutator method for the Rectangle class?
a.
getHeight
c.
getWidth
b.
translate
d.
isEmpty
 

 19. 

A _____________ is a collection of classes with a related purpose.
a.
package
c.
method
b.
import
d.
collection
 

 20. 

Which package is automatically imported in any Java program?
a.
java.system
c.
java.language
b.
java.lang
d.
java.util
 

 21. 

Which method checks whether a point lies within the rectangle?
a.
add
c.
translate
b.
getBounds
d.
contains
 

 22. 

Which method would you use to obtain the string "1234567890" from the string "123-456-7890"?
a.
isEmpty
c.
trim
b.
replace
d.
length
 

 23. 

Which of the following terms denotes the memory location of an object?
a.
implicit parameter
c.
encapsulation
b.
mutator method
d.
object reference
 

 24. 

What do object variables store?
a.
objects
c.
references
b.
classes
d.
numbers
 

 25. 

Assuming the following Java statement:
int num = 10;
What does the variable num store?
a.
A reference to the memory location where the value 10 is stored.
c.
An object representing the number 10.
b.
A reference to the int primitive type.
d.
The numeric value 10.
 

 26. 

What is the output of the following code:
Circle c1 = new Circle(3);
Circle c2 = c1;
c1.setRadius(4);
System.out.println(c2.getRadius());
a.
4
c.
6
b.
3
d.
c1
 

 27. 

What is the output of the following code:
int num1 = 6;
int num2 = num1;
num2 = num2 + 10;
System.out.println(num1);
a.
6
c.
4
b.
10
d.
16
 

 28. 

Complete this code fragment to ensure that the frame is shown:
JFrame frame = new JFrame();
a.
frame.setVisible(true);
c.
JFrame.setVisible();
b.
frame.visible = true;
d.
frame.setVisible();
 

 29. 

What is the nickname for the graphical user interface library in Java?
a.
Applet
c.
JComponent
b.
GUI
d.
Swing
 

 30. 

Place drawing instructions inside the __________ method, which is called whenever the component needs to be repainted.
a.
paintComponent
c.
paint
b.
draw
d.
drawComponent
 



 
Check Your Work     Start Over