Java Reference
In-Depth Information
2.
A vector is created, and three strings called
Tinker
,
Evers
, and
Chance
are added
to it. The method
removeElement(“Evers”)
is called. Which of the following
Vector
methods retrieve the string
“Chance”
?
a.
get(1);
b.
get(2);
c.
get(“Chance”);
3.
Which of these classes implements the
Map
interface?
a.
Stack
b.
Hashtable
c.
BitSet
8
Answers
1. c.
In past versions of Java, to store primitive types such as
int
in a table, objects
must be used to represent their values (such as
Integer
for integers). This isn't
true in Java 6: Primitive types are converted automatically to the corresponding
object class through a process called autoboxing.
2. a.
The index numbers of each item in a vector can change as items are added or
removed. Because “Chance” becomes the second item in the vector after “Evers” is
removed, it is retrieved by calling
get(1)
.
3. b.
Certification Practice
The following question is the kind of thing you could expect to be asked on a Java pro-
gramming certification test. Answer it without looking at today's material or using the
Java compiler to test the code.
Given:
public class Recursion {
public int dex = -1;
public Recursion() {
dex = getValue(17);
}
public int getValue(int dexValue) {
if (dexValue > 100)
return dexValue;
else