You are on page 1of 42

Chapter 1

34 questions
11 fill in the blank
8 true/false
15 multiple choice
Fill in the Blank Questions
1. The __________ is the part of a computer that follows instructions.
[processor]
2. A(n) __________ is a program that translates programs to a simpler language that the
computer can execute.
[compiler]
3. The Java interpreter translates a Java program from __________ to machine language.
[byte code]
4. A(n) __________ is an action that a Java object can perform.
[method]
5. Another term for __________ is information hiding.
[encapsulation]
6. A(n) __________ is a set of instructions that tells the basic strategery for solving a
problem.
[algorithm]
7. A(n) __________ is a program meant to be sent from one computer to another across the
world-wide web.
[applet]
8. A(n) __________ is a piece of information passed to a method.
[argument]
9. A(n) __________ is a digit that can only have the value 1 or 0.
[bit]
10. A(n) __________ is part of a program that has data associated with it and can perform
certain actions.
[object]
Optional Graphics Supplement Questions:
11. The __________ method of an applet is used to draw graphics and is invoked
automatically when the applet runs.
[paint]
True/False Questions
1. Main memory refers to the amount of storage space available on a computers disk
drive.
TRUE
FALSE
[FALSE]

1 of 42

2. Java is a high-level language.


TRUE
FALSE
[TRUE]
3. The Java compiler translates Java programs into machine language programs.
TRUE
FALSE
[FALSE]
4. Pseudocode is a mixture of English and a programming language.
TRUE
FALSE
[TRUE]
5. The computer will not display an error message when a logic error occurs.
TRUE
FALSE
[TRUE]
6. System.out is an example of a method.
TRUE
FALSE
[FALSE]
7. In Java, the double equal sign means "make equal to".
TRUE
FALSE
[FALSE]
8. Polymorphism is a classification system for organizing classes in Java.
TRUE
FALSE
[FALSE]
Multiple-Choice Questions
1. A bit can have __________ different values.
A. 2
B. 10
C. 100
[A]

D. 256

2. Bytes in auxiliary memory are grouped into __________.


A. bits
B. files
C. directories
[B]

D. programs

3. The kind of language that is easiest for people to use is


A. assembly language
B.
C. low-level language
D.
[D]

machine language
high-level language

4. Input to a compiler is called


A. a byte-code file B. source code
[B]

C. an executable file

D.

object code

5. The term __________ refers to a way of organizing classes that share properties.
A. object-oriented B. encapsulation
C. polymorphism
D. inheritance
[D]
6. __________ means that two or more methods can have different names in the same way
that an English word can have two or more meanings.
A. object-oriented B. encapsulation
C. polymorphism
D. inheritance
[C]

2 of 42

7. A(n) __________ occurs when a program has a grammatical mistake like missing
punctuation.
A. syntax error
B. run-time error
C. logic error
D. hidden error
[A]
8. If the computer displays an error message while executing your program, the program
contains a(n) __________.
A. syntax error
B. run-time error
C. logic error
D. hidden error
[B]
9. Invoking a method means
A. checking the method for errors
C. asking the method to do its job
[C]

B. designing the method


D. revising the method

10. In Java, a library of classes is called


A. a folder
B. a package
[B]

C. a directory

D. an application

11. The __________ is a program that supervises operation of the entire computer.
A. operating system B. compiler
C. interpreter
D. virtual machine
[A]
12. A(n) __________ is a unit of memory that contains eight binary digits.
A. bit
B. byte
C. object
D. class
[B]
13. Which of these is not a high-level language?
A. Java
B. BASIC
C. C++
[D]

D. assembly language

Optional Graphics Supplement Questions:


14. The point (0, 0) is in the __________ of the screen in the Java coordinate system.
A. upper left-hand corner
B.
upper right-hand corner
C. lower left-hand corner
D.
lower right-hand corner
E. center
[A]
15. Which of the following is information passed by parameter(s) to fillOval?
A. the fill color
B. the line color
C. the width of the bounding rectangle
D. the coordinates of the lower-right corner of the bounding rectangle
[C]

Chapter 2
39
15
13
13

questions
fill in the blank
true/false
multiple choice

3 of 42

Fill in the Blank Questions


1. Every variable in Java must be __________ before it is used.
[declared]
2. Single quotes are used with constants of the __________ type.
[char]
3. __________ is the integer type you should use if you're not sure which one is best.
[int]
4. An assignment statement always has a single __________ on the left side of the
assignment operator.
[variable]
5. A(n) __________ is used to change the type of a value.
[type cast]
6. The value of 42 % 10 is __________.
[2]
7. Double quotes are used with constants of the __________ type.
[String]
8. The __________ operator is used to connect two strings to make one longer string.
[concatenation or +]
9. To include a double quote inside a character string, you must use a(n) __________
character.
[escape]
10. nextInt and nextLine are two methods in the __________ class.
[Scanner]
11. __________ should explain non-obvious aspects of a program and should not be
redundant with the code.
[comments]
12. Using __________ variable names helps make a program self-documenting.
[meaningful]
13. A variables __________ determines the kind of value that it can hold.
[type]
14. __________ rules determine the order of operations if the order is not determined by
parentheses.
[precedence]
15. In a method invocation, the name that comes before the dot is the __________.
[calling object]
True/False Questions
1. An upper-case letter is considered to be the same character as a lower-case letter in
Java.
TRUE
FALSE
[FALSE]

4 of 42

2. The boolean type has only two values.


TRUE
FALSE
[TRUE]
3. A variable can appear on both sides of the assignment operator in the same assignment
statement.
TRUE
FALSE
[TRUE]
4. 3.65e2 is a legal integer constant in Java.
TRUE
FALSE
[FALSE]
5. Use of a type cast from double to int sometimes causes values to be rounded.
TRUE
FALSE
[FALSE]
6. A single declaration can include both initialized and uninitialized variables.
TRUE
FALSE
[TRUE]
7. Arithmetic with floating-point numbers is not exact.
TRUE
FALSE
[TRUE]
8. The value of 5 / 2 and the value of 5.0 / 2 are the same.
TRUE
FALSE
[FALSE]
9. ice-cream is an illegal identifier in Java.
TRUE
FALSE
[TRUE]
10. Values of a class type are simple values that are not made up of values of other types.
TRUE
FALSE
[FALSE]
11. There is no official limit on the length of variable names in Java.
TRUE
FALSE
[TRUE]
12. A common practice that is used in the textbook is to start the names of variables with a
capital letter.
TRUE
FALSE
[FALSE]
Optional Graphics Supplement Questions:
13. showMessageDialog is a JOptionPane method that can get input from the user.
TRUE
FALSE
[FALSE]

5 of 42

Multiple-Choice Questions
1. Which of the following is a class type?
A. int
B. double
[D]

C. char

2. Which of the following is not an integer type?


A. double
B. short
C. byte
[A]

D. String

D. int

3. Which of the following is a correct statement in Java?


A. apes = monkeys + gorillas
B. tigers = 3
C. lions + tigers = cats;
D. zebras += 5;
[D]
4. println is a method used with __________
A. objects of the String class
C. the System.out object
[C]

B. the System.in object


D.
the Scanner class

5. Which of the following assignments would not be allowed without a typecast?


A. assigning a short value to a long variable
B. assigning a byte value to a double variable
C. assigning an int value to a float variable
D. assigning a double value to a long variable
[D]
6. Which of the following operators has the highest precedence?
A. unary +
B. binary +
C. %
[A]

D. *

7. In which expression could the parentheses be removed without changing the value of
the expression?
A. x * (y + z)
B. (w x) / 3
C. x * 3 /(y + 2)
D. (y % 3) + 2
[D]
8. Which statement best describes the statement: x++;
A. It is incomplete and will cause a compiler error message if not modified.
B. It will add 1 to the value of x.
C. It will add 2 to the value of x.
D. It will make the new value of x be the absolute value of the old value of x.
[B]
9. The characters // in a line
A. are part of an expression that uses integer division
B. are part of an expression that uses integer division
C. mean that the rest of the line is a comment
D. are an escape sequence
[C]

6 of 42

10. A number like 60 in a program should


A. be replaced with a variable that has the same value
B. be replaced with a named constant
C. be explained by a comment
D. be written as '60' if used as an integer
[B]
11. Which of the following is a variable declaration?
A. "Enter number of apples:"
B. totalFruitCount = appleCount + orangeCount;
C. System.exit(0);
D. int appleCount;
[D]
12. Words that have predefined meanings in Java and cannot be used as variable names are
called
A. identifiers
B. comments
C. operators
D. key words
[D]
Optional Graphics Supplement Questions:
Which of the following is the name of a JOptionPane method that can get input from the
user?
A. nextInt
B. parseInt
C. getDialogInput
D. showInputDialog
[D]

Chapter 3
28 questions
6 fill in the blank
10 true/false
12 multiple choice
Fill in the Blank Questions
1. An ! in an expression means __________.
[not]
2. A list of statements enclosed in braces is called a(n) __________.
[compound statement]

7 of 42

3. A case label is used with a(n) __________ statement.


[switch]
4. A(n) __________ statement in a loop will cause the program to immediately exit the loop.
[break]
5. A(n) __________ is used for signaling the end of the input.
[sentinel value]
6. The order in which a program performs actions is called the __________.
[flow of control]
True/False Questions
1. Every statement with if must also include else.
TRUE
FALSE
[FALSE]
2. What is the value of the expression (x > 3) || (y < 3) if x has the value 1 and y has the
value 5?
true
false
[false]
3. The == operator can be used to see if two strings have the same characters.
TRUE
FALSE
[FALSE]
4. A multibranch if-else statement is one kind of nested if-else statement.
TRUE
FALSE
[TRUE]
5. The controlling expression of a switch statement must have a value that is an integer or
a character.
TRUE
FALSE
[TRUE]
6. The body of any while loop will be executed at least once.
TRUE
FALSE
[FALSE]
7. for loops and while loops use the same stopping mechanism.
TRUE
FALSE
[FALSE]
8. Java uses complete evaluation for Boolean expressions that use & instead of && and |
instead of ||.
TRUE
FALSE
[TRUE]
9. In ASCII, a capital 'Z' comes before a small 'a'.
TRUE
FALSE
[TRUE]
Optional Graphics Supplement Questions:

8 of 42

10. The drawstring method takes three parameters: a string and two numbers.
TRUE
FALSE
[TRUE]
Multiple-Choice Questions
1. What will be the value of x after the following section of code executes:
int x = 5;
if (x > 3)
x = x 2;
else
x = x + 2;
A. 1

B. 3

C. 5

D. 7

[B]
2. What will be the value of y after the following section of code executes:
int y = 4, z = 3;
if (y > 4)
{
z = 2;
y = y 1;
}
else
z = 1;
y = z;
A. 1

B. 2

C. 3

D. 4

[A]
3. What will be the value of w after the following section of code executes:
int w = 4, q = 3;
if (q > 5)
if (w == 7)
w = 3;
else
w = 2;
else
if (w > 3)
w = 1;
else
w = 0;
A. 0

B. 1

C. 2

[B]

9 of 42

D. 3

4. What will be the value of b after the following section of code executes:
int a = 4, b = 0;
if (a < 5)
b = 4;
else if (a < 10)
b = 3;
else if (a > 5)
b = 2;
else
b = 1;
A. 1

B. 2

C. 3

D. 4

[D]
5. What will the following code print?
int color = 3;
switch (color)
{
case 1:
case 2:
System.out.print("red ");
case 3:
System.out.print("blue");
break;
case 4:
System.out.print("purple");
break;
default:
System.out.print("gray");
}
A. red
D. gray

B. blue
E. red blue

C. purple

[B]
6. What will the following code print?
int count = 1;
while (count <= 3)
{
System.out.print(count + " ");
count++;
}
A. 1 2 3

B. 1 2

C. 3

[A]

10 of 42

D. 1 1 1

7. What will the following code print?


int count;
for (count = 4; count > 1; count--)
System.out.print(count + " ");
A. 1 2 3 4

B. 1 2 3

C. 4 3 2

D. 4 3 2 1

[C]
8. A(n) __________ is one kind of branching statement.
A. compound statement
B.
for statement
C. break statement
D. switch statement
[D]
9. A(n) __________ goes in the parentheses following the word if in an if-else statement.
A. parameter list
B. compound statement
C. nested if statement
D.
boolean expression
[D]
10. What happens when an expression uses == to compare two string variables?
A. The value of the expression will be true if both strings have the same characters in
them.
B. The value of the expression will be true if both string variables refer to the same
object.
C. The expression will not be correct syntax and the program will not compile.
D. A run-time error will occur.
[B]
11. What is the correct way to end a programs execution normally?
A. exit();
B. exit(0);
C. System.exit();
D. System.exit(0);
[D]
Optional Graphics Supplement Questions:
12. How do you set the color of an oval?
A. By setting the drawColor field of the Graphics class.
B. By calling the setColor method of the Graphics class.
C. By calling the set method of the Color class.
D. By passing a Color object as a parameter to the drawOval method.
[B]

Chapter 4
34 questions
13 fill in the blank
12 true/false
9 multiple choice

11 of 42

Fill in the Blank Questions


1. A(n) __________ is an action that an object can take and is specified in the class
definition.
[method]
2. Compiling a file called Game.java will produce a file called __________.
[Game.class]
3. A(n) __________ is a data item that belongs to an object.
[instance variable]
4. __________ is the word used to say that there are no restrictions on the use of a method
or data item.
[public]
5. The reserved word __________ can be used as a name for the calling object.
[this]
6. Names of mutator methods usually begin with __________.
[set]
7. The interface of a class consists of comments, __________, and defined constants.
[headings of public methods]
8. To create an object of a class type, the word __________ is used.
[new]
9. One kind of method returns a value. The other kind of method is called a(n) __________.
[void-method]
10. A __________ is the definition of a kind of object.
[class]
11. The __________ of a method definition is enclosed between braces.
[body]
12. A variable declared inside a method is called a __________ variable.
[local]
Optional Graphics Supplement Questions:
13. The __________ method of an applet is called automatically when the applet is starting
up.
[init]
True/False Questions
1. All objects of the same class have the same data values.
TRUE
FALSE
[FALSE]
2. When a method call is executed, values from the method definition are substituted for
the arguments in the method call.
TRUE
FALSE
[FALSE]

12 of 42

3. Parameters of a primitive type are passed to methods using the call-by-value


mechanism.
TRUE
FALSE
[TRUE]
4. Encapsulation is the process of defining a class that has no public methods.
TRUE
FALSE
[FALSE]
5. Private methods are part of the interface of a class.
TRUE
FALSE
[FALSE]
6. A variable of class type does not store an object of that class.
TRUE
FALSE
[TRUE]
7. An equals method should return a boolean value.
TRUE
FALSE
[TRUE]
8. A method can change the value of a variable of a primitive type that is an argument to
the method.
TRUE
FALSE
[FALSE]
9. A method can change the value of instance variables of an argument that is of a class
type.
TRUE
FALSE
[TRUE]
10. A Java method that does not return a value can have any number of return statements.
TRUE
FALSE
[TRUE]
Optional Graphics Supplement Questions:
11. drawString is a method of the Graphics class.
TRUE
FALSE
[FALSE]
12. An applet can be successfully compiled even if it has no init method and no paint
method.
TRUE
FALSE
[TRUE]

13 of 42

Multiple-Choice Questions
1. A method is invoked by
A. writing the name of the method followed by a colon and the name of the calling
object
B. writing the name of the calling object followed by a dot and a list of values in
parentheses
C. listing the name of the calling object and the name of the method inside
parentheses
D. writing the name of the calling object, followed by a dot, followed by the name of
the method and a list of values in parentheses
[D]
2. What can you tell about the method surpriseMe in the code below?
int something;
something = surpriseMe();
A. It has no parameters but has a return value.
B. It has one parameter but no return value.
C. It has no parameters and it has no return value.
D. It has one return value and an unknown number of parameters.
E. It has one parameter and an unknown number of return values.
[A]
3. A data item that can only be used within a method is called
A. a local variable
B. an instance variable
C. a global variable
D. a private variable
[A]
4. Normally all instance variables are given the qualifier
A. public
B. protected
C. private
[C]

D. static

5. One benefit of encapsulation is


A. the implementation of the class will be smaller
B. the implementation can be changed without changing programs that use the class
C. the interface of the class will be smaller
D. the interface can be changed without changing programs that use the class
[B]
6. When comparing two objects to see if they have the same contents, one should
A. use the = operator
B. use the == operator
C. define an equals method in the class and use it
D. use the equals method to see if they have the same variable name
[C]
7. A __________ method does not return a value.
A. null
B. static
C. void
[C]
Optional Graphics Supplement Questions:

14 of 42

D. recursive

8. Where does the Graphics object of an applet come from?


A. It is usually created in the init method and stored as an instance variable of the
applet.
B. It is inherited from the JApplet class.
C. It is a local variable of the applets init method.
D. It is created automatically and passed in to the applets paint method as a
parameter.
[D]
9. Which of the following is a method of the Graphics class?
A. drawRectangle
B. circleFill
C. drawOval
[C]

D. paint

Chapter 5
28 questions
10 fill in the blank
8 true/false
10 multiple choice
Fill in the Blank Questions
1. A __________ method is a method that can be invoked using the class name instead of an
object name.
[static]
2. The method used to convert from Character to char is __________.
[charValue]
3. The method used to convert from String to Float is __________.
[parseFloat]
4. A(n) __________ is a simplified version of a method that is easily verified and is used for
testing.
[stub]
5. In the technique of __________ design, the problem of designing a method is divided into
subproblems, which are then solved using the same technique.
[top-down]
6. A(n) __________ is a special kind of method used to initialize objects.
[constructor]
7. A(n) __________ is a collection of related classes that serves as a class library.
[package]
8. The __________ class provides the methods pow and round, among others.
[Math]
9. Integer and Double are __________ classes.
[wrapper]
10. A constructor with no parameters is called a __________ constructor.
[default]

15 of 42

True/False Questions
1. The object and dot can be omitted in a non-static method call if the calling object is the
this parameter.
TRUE
FALSE
[TRUE]
2. Instance variables cannot be referenced in the definition of any static method unless an
object (other than this) and dot precede the variable name.
TRUE
FALSE
[TRUE]
3. Java will use automatic type conversion before it will use overloading.
TRUE
FALSE
[FALSE]
4. It is possible to have two methods in the same class that have the same name, the
same number and types of arguments, but different return types.
TRUE
FALSE
[FALSE]
5. Constructors have return type void.
TRUE
FALSE
[FALSE]
6. A class may have more than one constructor.
TRUE
FALSE
[TRUE]
7. If you add at least one constructor to a class, no constructors will be automatically
created for the class.
TRUE
FALSE
[TRUE]
Optional Graphics Supplement Questions:
8. It is possible to make a component in an applet invisible after the applet has started
executing.
TRUE
FALSE
[TRUE]
Multiple-Choice Questions
1. The method __________ in the Math class returns the nearest whole number that is equal
to or less than its argument.
A. abs
B. min
C. round
D. floor
[D]
2. Which of these words is the name of a wrapper class?
A. int
B. float
C. Double
[C]

16 of 42

D. String

3. The term overloaded refers to


A. an error where more than one method matches a method call
B. two or more methods in the same class that have the same name
C. method calls where there are two many actual parameters
D. two or more methods in different classes that have the same name
[B]
4. Java will automatically define a constructor
A. if the programmer does not define a default constructor for a class
B. if the programmer does not define any constructors for a class
C. if the program refers to a constructor with no parameters
D. for every class defined in a program
[B]
5. A private instance variable
A. can never be modified by a method outside the class
B. can be modified by a method outside the class if it is returned by a method
C. can be modified by a method outside the class if it is a class type, using a mutator
method (assuming one exits)
D. can be modified by using an object name followed by a dot and then the name of
the instance variable
[C]
6. The name of a constructor
A. can be any legal identifier
B. must include the name of the package
C. will always be the word new
D. will always be the same as the name of the class
[D]
7. __________ is a special constant that is not an object but can be used to give a value to
any variable of class type.
A. void
B. this
C. null
D. false
[C]
8. A(n) __________ allows you to have a class object that corresponds to a value of a
primitive type.
A. wrapper class
B. type cast
C. constructor
D. static variable
[A]
Optional Graphics Supplement Questions:
9. When the user clicks a button, the event will be handled by an object of type __________.
A. ActionListener
B. EventHandler
C. ButtonListener
D. ActionHandler
[A]
10. In Java, an icon is __________ that can be added to a component.
A. a menu
B. a button
C. a sound
D. a picture
[D]

Chapter 6
28 questions
8 fill in the blank
11 true/false

17 of 42

9 multiple choice
Fill in the Blank Questions
1. The type of elements in an array is called the __________.
[base type]
2. Every array object has an instance variable called __________ that tells how many
elements are in the array.
[length]
3. An array can be initialized by enclosing a list of values in __________.
[braces]
4. When a program looks at array elements in order from first to last to find a value, it is
using the __________ algorithm.
[sequential search]
5. An array that uses more than one index is called a(n) __________ array.
[multidimensional]
6. The parameter to main is a(n) __________.
[array of Strings]
7. A two-dimensional array is implemented as a(n) __________.
[array of arrays]
Optional Graphics Supplement Questions:
8. The __________ method is the same as the drawPolygon method, except that it does not
draw a line from the last point back to the first point.
[drawPolyline]
True/False Questions
1. All data stored in an array must be the same type.
TRUE
FALSE
[TRUE]
2. The index to use with an array can be an expression whose value is computed when the
program runs.
TRUE
FALSE
[TRUE]
3. If one element from an array is passed as a parameter to a method, then the called
method can modify any element in the array.
TRUE
FALSE
[FALSE]
4. Every array has a method called equals that can be used to compare it to other arrays.
TRUE
FALSE
[FALSE]

18 of 42

5. An accessor method that returns an array should return a copy of an instance variable
array rather than the instance variable itself.
TRUE
FALSE
[TRUE]
6. In a two-dimensional array, all of the rows must have the same number of elements.
TRUE
FALSE
[FALSE]
7. The size of an array in Java is determined when the program is compiled.
TRUE
FALSE
[FALSE]
8. You can change the size of an array by assigning a new value to the length instance
variable.
TRUE
FALSE
[FALSE]
9. The first element in an array is accessed using zero as an index.
TRUE
FALSE
[TRUE]
10. Arrays in Java are objects.
TRUE
FALSE
[TRUE]
11. Selection sort is not one of the easier to understand sorting algorithms, but it is one of
the most efficient.
TRUE
FALSE
[FALSE]
Multiple-Choice Questions
1. The lowest index that can be used with an array
A. is zero
B. is one
C. is determined by the array declaration
D. changes as the program runs
[A]
2. The highest index that can be used with an array
A. is the number of elements in the array
B. is the number of elements in the array minus one
C. is determined by the array declaration
D. changes as the program runs
[B]
3. What will happen if a program uses an array index that is out of bounds?
A. The compiler will give an error message and will not compile the program.
B. The compiler will give a warning but will still compile the program.
C. The program will compile but Java will give an error message when the program
runs.
D. The program will compile and run with no error messages but might give incorrect
results.
[C]

19 of 42

4. Which statement best describes an array of 10 elements where the elements are of
class String?
A. 10 String objects will be created when the array is created.
B. 10 String objects must be created before the array is created.
C. The array will be created with the elements equal to null.
D. Elements of an array cannot be a class type.
[C]
5. Selection sort works by repeatedly
A. using the position of elements to split the list into two sublists of equal size
B. finding the smallest element in the remainder of the list and moving it forward
C. comparing adjacent elements in the list and swapping them if they are out of order
D. using a threshold value to split the list into two sublists where one sublist's elements
are greater than the threshold and the other sublist's elements are less than the
threshold
[B]
6. Which of the following is correct Java code?
A. int[10] list;
B. int list[10];
C. int list = new int[10];
D. int[] list = new int[10];
[D]
7. The main method of a program has
A. no parameters
B. one String parameter
C. one parameter which is an array of String values
D. an array of integers as the first parameter and an array of strings as the second
parameter
[C]
Optional Graphics Supplement Questions:
8. What is the main difference between a text field and a text area?
A. A text area can display more than one line and a text field can only display one line
of text.
B. A text field can be changed by the user and a text area cannot.
C. A text area has one or more text fields inside it.
D. A text area has a setText method but a text field does not.
[A]
9. How are the points of a polygon specified?
A. By repeated calls to the drawPolygon method, with each call specifying one x
coordinate and one y coordinate.
B. By passing an array of numbers that contains alternating x and y coordinates.
C. By passing two arrays of numbers, one containing x coordinates and the other
containing y coordinates.
D. By passing in a two-dimensional array of numbers that contains both x and y
coordinates.
[C]

Chapter 7

29 questions
12 fill in the blank

20 of 42

12 true/false
5 multiple choice
Fill in the Blank Questions
1. A(n) __________ is defined by adding instance variables and methods to an existing class.
[derived class or child class]
2. Inheritance can be used to create a new class by adding to an existing __________ class.
[base or parent]
3. When a class has a method that has the same name and the same number and types of
parameters as an inherited method, then the method __________ the inherited method.
[overrides]
4. The constructor of a derived class can access the constructor of its base class by using
the reserved word __________.
[super]
5. The reserved word __________ can be used as a name for another constructor in the
same class.
[this]
6. The reserved word __________ between two class names at the beginning of a class
definition indicates that the first class inherits from the second.
[extends]
7. In Java, every class is a descendant of the class __________.
[Object]
8. __________ binding is when the meaning of a method invocation is not bound to it until
the program is run.
[dynamic or late]
9. __________ means "many forms". In programming, it allows different objects to use
different method actions for the same method name.
[polymorphism]
10. A(n) __________ method is one which has no body and is meant to be overridden in every
derived class.
[abstract]
11. Adding the __________ modifier to a method heading prevents derived classes from
overriding the method.
[final]
12. A(n) __________ specifies headings for methods that must be defined by an
implementing class.
[interface]
True/False Questions
1. Instance variables that are private in a base class can be accessed in the definition of a
method in a derived class.
TRUE
FALSE
[FALSE]

21 of 42

2. Private methods are not inherited.


TRUE
FALSE
[TRUE]
3. If a constructor includes a call to the constructor of the base class, then the call must be
the first action in the constructor.
TRUE
FALSE
[TRUE]
4. An object of a derived class has the type of the derived class and also the type of every
ancestor class.
TRUE
FALSE
[TRUE]
5. A method in a derived class may not re-use any method name used in an ancestor
class.
TRUE
FALSE
[FALSE]
6. If class Able inherits from class Baker, and class Baker inherits from class Charlie, then
class Able inherits from class Charlie.
TRUE
FALSE
[TRUE]
7. The keyword this can be used as a method name that refers to a constructor.
TRUE
FALSE
[TRUE]
8. The expression super.super.foo() is legal as long as the foo method is defined in the
appropriate class.
TRUE
FALSE
[FALSE]
9. You can assign an object of an ancestor class to a variable of a derived class type.
TRUE
FALSE
[FALSE]
Optional Graphics Supplement Questions:
10. Every class derived from JFrame has a paint method.
TRUE
FALSE
[TRUE]
11. The close-window button of a JFrame GUI generates an event which is handled by an
action listener.
TRUE
FALSE
[FALSE]

22 of 42

12. The setSize method is commonly used to change the size of an applet.
TRUE
FALSE
[FALSE]
Multiple-Choice Questions
1. The expression super.foo() in a method
A. is a call to a method named super.foo in the same class
B. is a call to the foo method in the base class
C. is a call to the constructor of the class named foo
D. is a syntax error
[B]
2. Suppose that class Able inherits from class Baker, with a1 and b1 referring to objects of
class Able and Baker respectively. Which statement best describes how objects of classes
Able and Baker could be assigned to variables?
A. an object of class Able could be assigned to b1, and an object of class Baker could
be assigned to a1
B. an object of class Able could be assigned to b1, but an object of class Baker could
not be assigned to a1
C. an object of class Baker could be assigned to a1, but an object of class Able could
not be assigned to b1
D. an object of class Able could not be assigned to b1, and an object of class Baker
could not be assigned to a1
[B]
3. What determines whether a method definition in a derived class or an ancestor class
will be used?
A. the return type of the method
B. the type of the variable that names the object
C. the object's place in the inheritance chain
D. the derived class's descendants
[C]
4. An
A.
B.
C.
D.
[A]

abstract class
is a class which
is a class which
is a class which
is a class which

cannot be instantiated
has no methods
has only abstract methods
has only overridden methods

5. Which statement best describes overriding a method?


A. Methods in a base class and derived class have the
visibility modifiers.
B. Methods in a base class and derived class have the
number and types of parameters.
C. Methods in a base class and derived class have the
return types.
D. Methods in a base class and derived class have the
or types of parameters.
[B]

Chapter 8
25 questions
7 fill in the blank

23 of 42

same name but different


same name and have the same
same name but have different
same name but different number

9 true/false
9 multiple choice
Fill in the Blank Questions
1. The part of the code that tells what the program will do in normal circumstances is
called the __________.
[try-block]
2. The part of the code that tells what to do when an exception occurs is called the
__________.
[catch-block]
3. An exception is a(n) __________.
[object]
4. Exception-handling code can get more information about the exception by using the
__________ method.
[getMessage]
5. A method that includes a throw statement but does have a corresponding catch must
include a(n) __________ in its heading.
[throws-clause]
6. Statements in a(n) __________ block will be executed regardless of whether or not an
exception is thrown.
[finally]
7. __________ are often the only methods in an exception class, other than inherited
methods.
[constructors]
True/False Questions
1. A throw statement is only allowed inside a catch-block.
TRUE
FALSE
[FALSE]
2. A program is not allowed to have more throw statements than catch-blocks.
TRUE
FALSE
[FALSE]
3. Programmer-defined exception classes must be derived from a previously defined
exception class.
TRUE
FALSE
[TRUE]
4. ArrayIndexOutOfBoundsException is an exception that does not need to be caught or
declared in the method heading.
TRUE
FALSE
[TRUE]

24 of 42

5. catch-blocks should be in order from most general to most specific.


TRUE
FALSE
[FALSE]
6. catch-blocks may have any number of parameters.
TRUE
FALSE
[FALSE]
7. Every exception class is an ancestor of the class Exception.
TRUE
FALSE
[FALSE]
8. Any method that includes a throw statement must also include a catch-block.
TRUE
FALSE
[FALSE]
9. Exceptions that are descendants of the class RuntimeException do not have to be
caught or declared.
TRUE
FALSE
[TRUE]
Multiple-Choice Questions
1. A catch-block
A. is a special method used in exception handling
B. allows the user to specify what will happen next in the program
C. is not allowed in the same method as a try-block
D. contains code that is executed when an exception occurs
[D]
2. The purpose of the exception-handling mechanism in Java can best be described as
A. to simplify the code for normal circumstances
B. to provide an alternative for if-else statements
C. to reduce running time of programs
D. to reduce debugging time of programs
[A]
3. When an object is thrown
A. it is deleted and can no longer be used
B. execution resumes with the next executable statement
C. control passes to a catch-block
D. the object is unavailable until the catch-block finishes execution
[C]
4. When a catch-block finishes execution
A. the program continues in the try-block that was previously executing
B. the program returns to the beginning of the try-block to re-execute it.
C. the program continues with the next statement after the try-block and catch-blocks
D. the program stops execution
[C]

25 of 42

5. A programmer-defined exception class


A. can be derived from any existing class
B. should provide two or more constructors that set up the message for the exception
C. should not have more than one instance variable
D. should contain at least one int variable to store the exception code number
[B]
6. Overuse of exceptions
A. is not an issue because exceptions may be used freely
B. is not an issue because the compiler restricts programmer-defined exceptions
C. is a problem because it causes an excessive number of class definitions
D. is a problem because it results in unrestricted flow of control
[D]
7. catch-blocks are located
A. at the beginning of the method
B. at the end of the method
C. before a try-block
D. after a try-block
[D]
8. The parameter to the Exception class constructor
A. is a String that will be the message for the exception
B. is an int that will be the exception code number
C. tells the statement where execution should resume
D. is a boolean telling whether or not the program should terminate
[A]
9. What happens if the catch-block of a more general exception comes before the catchblock of a more specific exception?
A. Both catch-blocks will execute when the more general exception occurs.
B. Both catch-blocks will execute when the more specific exception occurs.
C. The more general catch-block will never execute.
D. The more specific catch-block will never execute.
[D]

Chapter 9
28 questions
11 fill in the blank
10 true/false
7 multiple choice

26 of 42

Fill in the Blank Questions


1. A(n) __________ is an object that takes data from a source or delivers data to its
destination.
[stream]
2. Files that are considered to be a string of characters and can easily be opened with an
editor are called __________ files.
[text]
3. The preferred class for output to a text file is __________.
[PrintWriter]
4. __________ to a file means to add data to the end of the file.
[appending]
5. The method __________ in the BufferedReader class can be used to read a line of input
from a file.
[readLine]
6. The class __________ can be used to break a string up into individual words.
[StringTokenizer]
7. All output streams have a method called __________ that writes all buffered data to the
file.
[flush]
8. The class __________ provides a method to find out if a given file already exists.
[File]
9. When a program tries to read beyond the end of a file, the read method returns the
value __________.
[-1]
10. The print method of PrintWriter will automatically call the __________ method of objects
passed to it as parameters.
[toString]
11. A(n) __________ name gives the name of a file and also tells what directory (or folder) the
file is in.
[path]

27 of 42

True/False Questions
1. A disadvantage of binary files is that are less efficient to process than other files.
TRUE
FALSE
[FALSE]
2. A file variable declared inside a try-block will not be accessible outside of the try-block.
TRUE
FALSE
[TRUE]
3. Careless use of the FileOutputStream constructor can result in lost files.
TRUE
FALSE
[TRUE]
4. When a program will be appending to a file rather than creating a new file, the string
"append" should be added as a second parameter to the constructor for FileOutputStream.
TRUE
FALSE
[FALSE]
5. The preferred way to open a text file for input is to pass the file name to the constructor
for BufferedReader.
TRUE
FALSE
[FALSE]
6. The way to find out if a tokenizer has more tokens is to use the boolean instance
variable more.
TRUE
FALSE
[FALSE]
7. The readLine method in BufferedReader returns the value null if there is no more data to
read from the file.
TRUE
FALSE
[TRUE]
8. ObjectInputStream methods that try to read past the end of a file will cause an
EOFException.
TRUE
FALSE
[TRUE]
9. If data in a stream flows out of a file then the stream is an output stream.
TRUE
FALSE
[FALSE]
10. Your program should call the close method when it is finished with a file because
otherwise the next program that needs to use the file will not be able to open it.
TRUE
FALSE
[FALSE]
Multiple-Choice Questions
1. Every program that does file I/O
A. must include the line include io.java somewhere in the program
B. can do input from a file or output to a file but not both
C. must be designed specifically for the operating system in which it will run
D. must include the line import java.io.* near the beginning
[D]

28 of 42

2. Opening a text file for writing


A. requires use of the PrintWriter constructor
B. requires use of the FileOutputStream constructor
C. requires use of the PrintWriter constructor and the FileOutputStream constructor
D. does not require use of any constructors
[C]
3. If a new output text file cannot be created
A. a FileNotFoundException will be thrown
B. a FileNotCreatedException will be thrown
C. the program will stop executing with an error message
D. the program will continue executing and might produce incorrect results
[A]
4. If an open file is not closed when the program finishes executing
A. a FileNotClosed exception will be thrown
B. the contents of the file will be lost
C. Java will close the file but it is better to explicitly close the file
D. no other program will be able to open the file
[C]
5. The classes used to open a binary file for writing are
A. PrintWriter and FileOutputStream
B. ObjectOutputStream and FileOutputStream
C. PrintWriter and ObjectOutputStream
D. BufferedWriter and ObjectOutputStream
[B]
6. A good programming practice for I/O in Java is
A. have objects do their own I/O
B. design a single class to do all I/O for the program
C. avoid file I/O since it is inefficient
D. never append to a file
[A]
7. If the second parameter to the FileOutputStream constructor is __________, a program
will be able to append to a file.
A. the boolean value true
B. the character 'a' or 'A'
C. the character '+'
D. the string "append"
[A]

Chapter 10
26 questions
12 fill in the blank
10 true/false
8 multiple choice

29 of 42

Fill in the Blank Questions


1. Vectors can be thought of as __________ that can grow and shrink.
[arrays]
2. The vector method that takes an index as a parameter and returns an element of the
vector is __________.
[elementAt]
3. The vector method that tells how many elements are currently in the vector is
__________.
[size]
4. Usually the __________ node is the only node in the list for which there is a named
variable.
[head]
5. A(n) __________ is an object that allows you to step through a list and perform some
action for each element of the list.
[iterator]
6. To make a linked list that can contain different kinds of elements, the data instance
variable should be defined as __________.
[Object]
7. A(n) __________ is a linked list where a program can easily move backward in the list as
well as forward.
[doubly-linked list]
8. The vector method __________ can be used to reduce the amount of memory used by the
vector to the minimum necessary.
[trimToSize]
9. Each node in a linked list has some data and a(n) __________ to another node.
[link or reference]
10. The process
of recycling the memory used by deleted nodes is called automatic
__________.
[garbage collection]
11. A class defined within another class is called a(n) __________.
[inner class]
12. The __________ of a vector is the type of elements that can be added to the vector.
[base type]
True/False Questions
1. A program that uses vectors must include the line: import java.vector.*;
TRUE
FALSE
[FALSE]
2. If the current size of a vector is 10, the method call v.setElementAt(newEl, 10) will add
newEl as the 11th element of the vector.
TRUE
FALSE
[FALSE]

30 of 42

3. Any vector that is not parameterized (has no type parameter) will have a base type of
Object.
TRUE
FALSE
[TRUE]
4. A tree is a linked data structure where links form loops among the elements.
TRUE
FALSE
[FALSE]
5. A vector created with the default constructor will have 10 elements and will add 10
elements whenever it needs to increase its capacity.
TRUE
FALSE
[FALSE]
6. A vector can grow and shrink during execution of a program.
TRUE
FALSE
[TRUE]
7. The square bracket notation used with arrays can also be used with vectors.
TRUE
FALSE
[FALSE]
8. The base type of a vector is specified in angular brackets after the class name, Vector.
TRUE
FALSE
[TRUE]
9. A primitive type cannot be the base type of a vector.
TRUE
FALSE
[TRUE]
10. The Vector method elementAt always returns a result of type Object.
TRUE
FALSE
[FALSE]
Multiple-Choice Questions
1. One disadvantage of vectors is
A. they have a limited capacity
B. they can only contain primitive types
C. they can only contain objects
D. they often cause exceptions
[C]
2. A number passed as an argument to the Vector constructor
A. causes a compiler error
B. indicates the type of elements that will be stored in the vector
C. determines the initial capacity of the vector
D. makes the number the first element of the vector
[C]

31 of 42

3. A program can make a copy of a vector by


A. using the assignment operator
B. using the clone method of Vector
C. using the copy method of Vector
D. writing special-purpose code
[B]
4. Links in a linked list are usually
A. references
B. integers
[A]

C. arrays

D. vectors

5. In the textbook's implementation of a linked list, the statement used to go from one
node to the next was a statement like:
A. position.next();
B. position++;
C. position.addElement(1);
D. position = position.getLink();
[D]
6. What happens to nodes that are deleted from a linked list?
A. The memory they used is reclaimed for other uses automatically.
B. The memory they use is reclaimed when the method System.garbageCollect is
called.
C. The memory they use is not reclaimed until the head node is deleted.
D. The memory they use is not available for other uses until the program terminates.
[A]
7. Where is the easiest place to add new nodes to a linked list?
A. At the beginning of the list.
B. At the end of the list.
C. Wherever the current position is.
D. Wherever there is an empty position.
[A]
8. The elementAt method
A. has two parameters
B. only returns values of primitive types
C. is typically used with a type cast
D. returns null if the requested element does not exist
[C]

Chapter 11
25 questions
5 fill in the blank
11 true/false
9 multiple choice
Fill in the Blank Questions
1. When a method definition contains an invocation of itself, the method is said to be
__________.
[recursive]

32 of 42

2. A __________ is a case with no recursive calls.


[stopping case or base case]
3. If every case of a recursive method includes calls to itself, the result will be __________.
[infinite recursion]
4. A rewritten recursive method that uses a loop instead of recursion is called a(n)
__________ version of the method.
[iterative]
5. Binary search cannot be used with an array that is not __________.
[sorted]
True/False Questions
1. The main reason for using recursion is to make a program easier to understand.
TRUE
FALSE
[TRUE]
2. A recursive method needs to have an if-else or some other branching statement that
leads to different cases.
TRUE
FALSE
[TRUE]
3. A recursive method should only contain one call to itself.
TRUE
FALSE
[FALSE]
4. A recursive method must contain at least one case where it does not call itself.
TRUE
FALSE
[TRUE]
5. The error that results from having too many stopping cases is called stack overflow.
TRUE
FALSE
[FALSE]
6. Any method written with recursion can be rewritten to do the same thing without using
recursion.
TRUE
FALSE
[TRUE]
7. A version of a method that uses recursion is usually less efficient than a version of the
method that does not use recursion.
TRUE
FALSE
[TRUE]
8. Every method call where a method calls another method with the same name is a
recursive method call.
TRUE
FALSE
[FALSE]
9. Using binary search with an array requires the elements in the array to be sorted.
TRUE
FALSE
[TRUE]

33 of 42

10. A binary search method can find an element in an array of 1000 elements using about
10 comparisons, whereas a linear search method would require about 500 comparisons.
TRUE
FALSE
[TRUE]
11. The merge sort algorithm is much more efficient than the selection sort algorithm.
TRUE
FALSE
[TRUE]
Multiple-Choice Questions
1. The problem solved by a recursive call
A. should be a smaller version of the original problem
B. might be the same as the original problem
C. should be a bigger version of the original problem
D. is usually unrelated to the original problem
[A]
2. What will be the value returned by the method mystery1 below if called with the
parameter 3?
public static int mystery1(int n)
{
if (n < 1)
return 3;
else
return 3 + mystery1(n 1);
}
A. 3
B. 6
C. 9
D. 12
[D]
3. In the binary search case study, why was the method find also written, instead of using
just search?
A. because search by itself is not guaranteed to terminate
B. to provide both a recursive and non-recursive solution to the problem
C. because search by itself would require additional parameters that the user should
not have to understand
D. to provide a means of checking the results of search
[C]
4. What will be the value returned by the method mystery2 below if called with the
parameter 3?
public static int mystery2(int n)
{
if (n <= 1)
return 1;
else
return 2 * mystery2(n 1);
}
A. 1
B. 2
C. 4
D. 8
E. no value will be returned because the recursion will not terminate
[C]

34 of 42

5. What will be the value returned by the method mystery3 below if called with the
parameter 4?
public static int mystery3(int n)
{
if (n > 7)
return 1;
else if (n == 3)
return 3 + mystery3(n + 1);
else
return 1 + mystery3(n + 1);
}
A. 1
B. 5
C. 6
D. 8
E. no value will be returned because the recursion will not terminate
[B]
6. What will be the value returned by the method mystery4 below if called with the
parameter 3?
public static int mystery4(int n)
{
if (n < 1)
return 1;
else
return 2 + mystery4(n + 1);
}
A. 3
B. 5
C. 7
D. 9
E. no value will be returned because the recursion will not terminate
[E]
7. A method is recursive if
A. it contains a loop
B. it contains an invocation of itself
C. it has no parameters
D. it returns a value that is not a primitive type
[B]
8. What happens if a recursive method does not have a base case?
A. it will produce incorrect results because it does not call itself
B. a compiler error
C. infinite recursion
D. a MissingBaseCaseException occurs
[C]
9. Recursion should be used
A. whenever possible
B. when efficiency and performance are important
C. when it makes a program easier to understand
D. when there is no non-recursive alternative
[C]

Chapter 12
30 questions
14 fill in the blank
6 true/false
10 multiple choice

35 of 42

Fill in the Blank Questions


1. A(n) __________ is an object that represents an action such as clicking a mouse button or
pressing a key.
[event]
2. A(n) __________ has methods that tell what will happen when it receives an event.
[listener or listener object]
3. Programs that use Swing objects must include the line import __________; near the
beginning of the file.
[javax.swing.*]
4. Instead of being added directly to a JFrame object, labels and other components are
added to the __________ of the frame.
[content pane]
5. A(n) __________ is the unit of measurement for size and location in Swing and is the
smallest unit of space on the screen that a program can set.
[pixel]
6. The object that arranges labels and other components in a frame is called a(n)
__________.
[layout manager]
7. A button fires __________ events.
[action]
8. __________ is a Swing class that allows the user to enter a single line of text.
[JTextField]
9. The __________ places each component into one of five regions: NORTH, SOUTH, EAST,
WEST, and CENTER.
[BorderLayout manager]
10. The __________ places components from left to right in the order in which they were
added.
[FlowLayout manager]
11. The __________ arranges components in rows and columns and makes all components
the same size.
[GridLayout manager]
12. You can find out which button was clicked by calling the __________ method of the event
object.
[getActionCommand]
13. A(n) __________ is a property of a class that says what methods the class must have.
[interface]
14. A(n) __________ is a kind of component that can have other components added to it.
[container]

36 of 42

True/False Questions
1. Swing can be viewed as an improved version of the Abstract Window Toolkit (AWT).
TRUE
FALSE
[TRUE]
2. In writing event-driven programs, the programmer often writes methods that are never
called from code that he or she writes.
TRUE
FALSE
[TRUE]
3. An object that fires events must register with a listener before it can be used in a
program.
TRUE
FALSE
[FALSE]
4. Every listener class must have the statement import java.awt.*; in its file.
TRUE
FALSE
[FALSE]
5. Any class that contains a method named actionPerformed is an action listener.
TRUE
FALSE
[FALSE]
6. An abstract class cannot be instantiated.
TRUE
FALSE
[TRUE]
Multiple-Choice Questions
1. Which method call would make the window myWindow show up on the screen?
A. myWindow.setVisible(true);
B. myWindow.show();
C. myWindow.display();
D. myWindow.showWindow(true);
[A]
2. A window listener class for a GUI program will often be derived from the class
A. WindowListener
B. JEventHandler
C. JWindowManager
D. WindowAdapter
[D]
3. The layout that allows components to be placed in the CENTER, NORTH, SOUTH, EAST,
or WEST is
A. FlowLayout
B. BorderLayout
C. CardLayout
D. GridLayout
[B]
4. The simplest layout is
A. FlowLayout
B. BorderLayout
[A]

C. CardLayout

D. GridLayout

5. The layout that allows components to be placed in rows and columns with each
component the same size is
A. FlowLayout
B. BorderLayout
C. CardLayout
D. GridLayout
[D]

37 of 42

6. The string parameter to the JButton constructor


A. tells which region to put the button in
B. tells the color of the button
C. tells what text will appear on the button
D. tells what should happen when the button is pressed
[C]
7. A program can tell which button was clicked by
A. using the getActionCommand method in the event object
B. using the getButtonLabel method in the event object
C. using the buttonName instance variable in the listener
D. using the second parameter of the ActionPerformed method
[A]
8. ActionListener is
A. a class
C. an instance variable
[B]

B. an interface
D.

a method

9. Which of the following is a container that is normally used with a layout manager?
A. JButton
B. JLabel
C. JTextArea
D. JPanel
[D]
10. The parseInt method is in the __________ class.
A. Integer
B. Int
C. Parser
[A]

D. Input

Chapter 13
25 questions
11 fill in the blank
6 true/false
8 multiple choice
Fill in the Blank Questions
1. A(n) __________ is a Java program designed to run from a document on the Internet.
[applet]
2. Documents designed to be read using a web browser are usually written in a language
called __________.
[HTML or Hypertext Markup Language]
3. Connections from one document to another are called __________.
[links]
4. The command used to begin a comment in HTML is __________.
[<!--]
5. A(n) __________ is a kind of path name for the Internet that tells where to find a
document.
[URL or Uniform Resource Locator]

38 of 42

6. __________ is a program that can automatically generate an HTML document that


describes a Java class.
[javadoc]
7. A(n) __________ is a program that allows an applet to be tested without using a web
browser.
[applet viewer]
8. One step in converting a Swing application to an applet is to remove the __________
method.
[main]
9. A __________ is a program that is used to read documents across the Internet.
[web browser]
10. An applet is a derived class of the Swing class __________.
[JApplet]
11. The first command in an HTML document should be __________.
[<HTML>]
True/False Questions
1. HTML is case sensitive.
TRUE
FALSE
[FALSE]
2. The command <IMG SRC=tiger.gif> could be used to display the picture file tiger.gif.
TRUE
FALSE
[TRUE]
3. Applets use the setSize method in the same way that Swing applications do.
TRUE
FALSE
[FALSE]
4. An HTML document will usually start with the command <H1>.
TRUE
FALSE
[FALSE]
5. All picture files must be in the same directory as the HTML document that displays
them.
TRUE
FALSE
[FALSE]
6. An applet does not normally have a main method.
TRUE
FALSE
[TRUE]
Multiple-Choice Questions
1. A title in HTML is defined
A. in the first line of the file
B. in the document head part of the file
C. in the document body part of the file
D. anywhere in the file
[B]

39 of 42

2. In HTML, a link to another document will include


A. NEXT
B. LINK
C. GOTO
[D]

D. HREF

3. It is sometimes necessary to use a Reload or Refresh button in a web browser


A. because web browsers keep copies of recently used pages
B. because many web pages have two different versions
C. when the address of a page is incorrect
D. when a page has moved to a different server
[A]
4. An applet class will usually be derived from the class
A. JApplet
B. JFrame
C. HTML
[A]

D. Object

5. Initialization statements in an applet are usually


A. placed in the constructor for the applet
B. placed in the init method of the applet
C. placed in the begin method of the applet
D. placed in the paint method of the applet
[B]
6. An
A.
B.
C.
D.
[D]

applet command in an HTML document specifies


the source file for the applet
the height and width of the applet
the source file, height, and width of the applet
the class file, height, and width of the applet

7. Which of the following has no closing command associated with it?


A. <HTML>
B. <H1>
C. <B>
D. <BR>
[D]
8. How is the size of an applet determined?
A. by using the setSize method
B. by specifying the height and width in the applet tag
C. by the user changing the size of the browser window
D. by the applets layout manager
[B]

Chapter 14
24 questions
12 fill in the blank
5 true/false
7 multiple choice
Fill in the Blank Questions
1. Menu items behave the same as __________, another kind of Swing component.
[buttons]
2. Entries on a menu are objects of the class __________.
[JMenuItem]

40 of 42

3. An icon is a small __________ that is in a standard format.


[picture]
4. A button can show both a string and an icon by passing the string to the constructor and
then passing the icon to the method __________.
[setIcon]
5. The createVerticalStrut is a static method of the __________ class.
[Box]
6. A __________ component is similar to a strut component but is more flexible.
[glue]
7. __________ is a class that implements the WindowListener interface by giving each
method in the interface an empty body.
[WindowAdapter]
8. The method __________ is used to release the resources of a JFrame when the window is
closed and is usually only used in a program with more than one window.
[dispose]
9. When the visibility of a component is changed, the __________ method should be called.
[validate]
10. The class __________ is used to add scroll bars to a JTextArea and certain other
components.
[JScrollPane]
11. The __________ class is used to give components a raised look or a recessed look.
[BevelBorder]
12. A __________ object allows you to specify the color of a border and also allows you to
specify the thickness of the top, bottom, left, and right sides of the border.
[MatteBorder]
True/False Questions
1. Swing allows nested menus.
TRUE
FALSE
[TRUE]
2. An icon may be added to a label.
TRUE
FALSE
[TRUE]
3. A BoxLayout object may be created either by a constructor or by use of the
createBoxLayout method in the Box class.
TRUE
FALSE
[FALSE]
4. Any object that includes the windowOpened and windowClosed methods (with the
proper parameters) implements the WindowListener interface.
TRUE
FALSE
[FALSE]

41 of 42

5. JMenuItem inherits from the class AbstractButton.


TRUE
FALSE
[TRUE]
Multiple-Choice Questions
1. What kind of event is fired when the user selects an item from a menu?
A. a MenuEvent
B. a CommandEvent
C. an ActionEvent D. a UserActionEvent
[C]
2. What class is used to set the scrollbar policy?
A. JScrollPane
B. JScrolledText
C. JScrollBarPolicy
[A]

D. JTextArea

3. Which of the following is not the name of a class that can be used to add a border to a
Swing component?
A. RaisedBorder
B. EtchedBorder
C. MatteBorder
D. LineBorder
[A]
4. Strut and glue components
A. can be added to Box components only
B. can be added only to a JPanel with the BoxLayout
C. can be added to a JPanel or a Box but should only be used with a Box
D. should be used with a Box or a JPanel with the BoxLayout
[D]
5. To keep a window from closing when the close button is clicked,
A. the programmer doesn't need to do anything
B. the programmer needs to write a windowClosing method
C. the programmer needs to add a call to the setDefaultCloseOperation method
D. the programmer needs to give the parameter WindowConstants.DO_NOTHING to the
constructor of the window object
[C]
6. The class used to convert a picture file to a Swing icon is
A. Icon
B. JIcon
C. ImageIcon
[C]

D. Image

7. The JButton and JMenuItem classes are derived from


A. Button
B. AbstractButton C. JMenuBar
[B]

D. ActionItem

42 of 42

You might also like