Sei sulla pagina 1di 6

Dan Chisholm Exam 9 Answers

Answers: Certified Java Programmer Mock Exam


No. Answer Remark
b
d strictfp super goto
1
g native
h
The escape sequences are as follows: '\b' (backspace), '\f'
(formfeed), '\n' (newline), '\r' (carriage return), '\t' (horizontal
2 e 5 tab), '\\' (backslash), '\"' (double quote), '\'' (single quote).
Yes, you must memorize the escape sequences! Just
remember "big farms need red tractors".
The modifier, abstract, is applicable to an interface
declaration, but its use is strongly discouraged; because
every interface is implicitly abstract. The modifiers, private
and protected, are applicable only to an interface declaration
a that is a member of a directly enclosing class declaration. If
3 abstract public
g an interface is not a member of a directly enclosing class, or
if the interface is a member of a directly enclosing interface;
then, the modifiers, private and protected, are not applicable.
An interface can not be final. The keywords, extends and
implements, are not modifiers.
A char is a 16 bit unsigned value; so none of the char values
b '\u0000' to '\uffff' 0
4 are negative and the minimum value is zero. The maximum
d to 65535
value is 216 - 1.
The positive infinity of type float is promoted to the positive
Prints:
5 f infinity of type double. NaN is not equal to anything
true,false,true
including itself.
Both operands of the first addition operator are promoted
from type char to int, and are evaluated as integral numeric
values. The right hand operand of the second addition
operator is of type String, so the result of the first addition
6 c Prints: 195ab
operator is converted to type String, and is concatenated
with the right hand operand. As evaluation of the expression
continues from left to right, the remaining operands are also
converted to type String.
A tightly encapsulated class may have public mutator
methods. If a tightly encapsulated class does not have non-
7 e None of the above
private mutator methods, then the class can be called
immutable.
b
notify notifyAll
8 c
wait
i

Page : 1
Dan Chisholm Exam 9 Answers

Answers: Certified Java Programmer Mock Exam


No. Answer Remark
The Math class declares four versions of the abs method;
each declares a pair of parameters of the same type. The
parameter pair can be of type int, long, float or double. The
return type is the same as the argument types. At run-time,
the arguments might not match the declared parameter types;
so one argument or both might require an implicit
9 a Prints: 10.0 conversion to an acceptable type. If both arguments are of
type byte, short or char, then both will be promoted to type
int. If only one argument is of type byte, short or char, then it
will be promoted to the type of the other argument. If both
arguments are of type int, long, float or double but the types
differ, then a primitive widening conversion will be applied
to one of the two arguments.
10 a Prints: -128,127
An int is a 32-bit signed integral value that is stored in two's
complement format. The left most bit is the sign bit. The
11 d Prints: true,true
sign bit is set to one for negative numbers and is set to zero
for positive numbers.
Long.equals overrides Object.equals. The Long.equals
method compares the data values contained in the Long
instances. The StringBuffer.equals method does not override
Object.equals. The StringBuffer.equals method compares the
reference values of the instances. Two distinct instances of
12 c Prints: true,false
StringBuffer will not have the same reference values; so the
equals method returns false. The StringBuffer.hashCode
method typically returns a value that is based on the internal
address of the StringBuffer instance. Two instances of
StringBuffer will not have the same hash code.
a
doubleValue
b
floatValue intValue
13 c
longValue
d
parseDouble
e
The Boolean.valueOf method returns a Boolean instance.
The Boolean.booleanValue method returns a primitive. The
14 f Prints: BbB
Boolean.TRUE field is a reference to an instance of type
Boolean that wraps the primitive value true.
15 b Prints: ffF
The Map interface organizes entries as key/value pairs. A list
16 c Set generally allows duplicate entries. A Set rejects duplicate
entries.

Page : 2
Dan Chisholm Exam 9 Answers

Answers: Certified Java Programmer Mock Exam


No. Answer Remark
HashSet is a subclass of AbstractSet and AbstractCollection;
therefore, it implements the Collection interface. HashMap
Prints: and Hashtable do not implement the Collection interface.
17 e
true,false,false Instead, HashMap extends AbstractMap and implements the
Map interface. Hashtable extends Dictionary and
implements the Map interface.
The hashCode contract requires that the hashCode method
returns the same value whenever it is invoked on the same
object more than once during an execution of a Java
application provided no information used in the equals
comparisons is modified. It is unlikely that the
Random.nextInt method will provide results consistent with
b
the hashCode contract. The hashCode methods of classes B
18 c B C D
and C will always return the same value during an execution
d
of the Java application and are therefore consistent with the
hashCode contract. Even so, the hashCode methods of
classes B and C are not very good, because they will cause
hashtables to place every instance of classes B and C in the
same bucket. The hashCode method of class D is legal and
will allow a hashtable to operate efficiently.
Objects A and B have references to each other, but no other
Objects refer to A and B. Objects A and B form an island of
islolated objects and are eligible for garbage collection. All
19 c C
three references, i1, i2 and i3, refer to Object C; so it is not
eligible for garbage collection when method m2 begins to
execute.
Local variables are not initialized automatically, and must be
initialized explicitly before attempting to access the value.
20 c Compile-time error
The local variable i3 will not be initialized if i1 is less than
or equal to zero; so the result is a compile-time error.
When char variables a and b are converted to String types
they are printed as *$. When not converted to String types
they are promoted to type int, and are printed as the numeric
sum of 0x2a and 0x24. At line 1, the expression, a + b, can
be evaluated as follows: 0x2a + 0x24 = 42 + 36 = 78. At line
21 a Prints: 78 ABC*$ 2, the first operand of the expression, " ABC" + a + b, is of
type String. Since one operand of the first addition operator
is of type String the other operand must be converted to type
String: (" ABC" + "*") + b = " ABC*" + b. The process is
repeated for the second addition operation: " ABC*" + b = "
ABC*" + "$" = " ABC*$"
22 b Prints: GFC203 The type of the argument is null and could be converted to

Page : 3
Dan Chisholm Exam 9 Answers

Answers: Certified Java Programmer Mock Exam


No. Answer Remark
either type GFC202 or GFC203 by method invocation
conversion; so both methods are applicable. The more
specific of the two, m(GFC203 x), is chosen. Type GFC203
is a subclass of type GFC202; so any argument that can be
passed to m(GFC203 x) can also be passed to method
m(GFC202 x) without causing a compile-time type error;
therefore, we can say that method m(GFC203 x) is more
specific than m(GFC202 x).
The two-parameter constructor of U does not explicitly
invoke the two-parameter constructor of T; therefore, the
23 f Compile-time error
constructor of U will try to invoke a no-parameter
constructor of T, but none exists.
The private fields and methods of the member classes are
available to the enclosing class. The private fields and
24 e Prints: Z.m1 Y.m1
methods of the member classes are also available to other
member classes.
The reference c2 is of the superclass type, A; so it can be
used to invoke only the method, m1, declared in class A. The
25 a Prints: AAA methods that overload the method name m1 in the
subclasses, B and C, can not be invoked using the reference
c2.
At run-time, the expression a+b is evaluated four times.
Each evaluation produces a new String instance containing
the value "AB". Each of the four instances has a unique
reference. If any two of the four instances appear as the
operands of the equality operator, then the result is always
false. When the intern method is invoked on the instance
referenced by variable c, then the instance is added to the
26 b Prints: false,true
String pool that is maintained by the system, and a reference
to the pooled String is returned. When the intern method is
invoked on the instance reference by variable d, then a
reference to the previously interned String is returned. The
left and right operands of the equality expression
c.intern()==d.intern() refer to the same instance; so the result
is true.
The two statements, int a=1 followed by a += ++a + a++,
can be rewritten as the single statement, a=(int)((1)+(++a +
a++)). Further evaluation produces a=(int)((1)+(2 + 2)).
27 c Prints: 5
Generally speaking, a compound assignment expression of
the form E1 op= E2 can be rewritten as E1=(T)((E1)op(E2))
where T is the type of E1.
28 f None of the above The program compiles and runs without error and prints 112.

Page : 4
Dan Chisholm Exam 9 Answers

Answers: Certified Java Programmer Mock Exam


No. Answer Remark
It is necessary to remember that arrays are Cloneable
objects. Furthermore, a two dimensional array is also a
single dimensional array of single dimensional arrays. At
line 2, a two dimensional array of int primitives is converted
to a single dimensional array with components of type
Object where each Object is a single dimensional array. The
loop iterates through each element of the Object array. Since
each element is actually a reference to a single dimensional
array of integer primitives a conversion from type Object to
an int array is legal.
Although the reference parameters i1 and i2 are reassigned
inside of m1, the change has no impact outside of m1. Array
29 c Prints: 1,3
references are passed by value: the invoked method gets a
copy of the array reference.
The declaration A11[] a1 = new A11[1] declares a variable
a1 that references an array that contains one component of
type A11. The declaration A11[][] a2 = new A11[2][]
declares a variable a2 that references an array that contains
two components of type A11[]. In other words, the array
referenced by a2 contains two reference variables, and each
is able to reference a subarray. The initial value of the
subarray references is null. The size of the subarrays has not
been specified. The declaration A11[][][] a3 = new
A11[3][][] declares a variable a3 that references an array that
contains three components of type A11[][]. In other words,
the array referenced by a3 contains three reference variables,
and each is able to reference a subarray. The initial value of
each subarray reference is null. The dimensions of the
30 b Prints: A11 subarrays have not been specified. At line 5, a reference to
the array referenced by a1 is assigned to each of the two
components of the array referenced by a2, a2[0] = a2[1] =
a1. At line 6, a reference to the array referenced by a2 is
assigned to each of the three components of the array
referenced by a3, a3[0] = a3[1] = a3[2] = a2. In other words,
after line 6, each component of the array referenced by a3 is
a reference to the array referenced by a2, and each element
of the array referenced by a2 is a reference to the array
referenced by a1, and the array referenced by a1 contains a
reference to an instance of class A11. Every element of the
multi-dimensional array referenced by a3 contains a
reference to a single instance of class A11. The print method
invokes the toString method on the instance, and produces
the output, A11.

Page : 5
Dan Chisholm Exam 9 Answers

Page : 6

Potrebbero piacerti anche