Exam 9 Answers

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Exam 9 Answers as PDF for free.

More details

  • Words: 2,038
  • Pages: 6
Dan Chisholm

Answers

Answers: Certified Java Programmer Mock Exam Answer Remark

No. 1

Exam 9

b d strictfp super goto g native h The escape sequences are as follows: '\b' (backspace), '\f' (formfeed), '\n' (newline), '\r' (carriage return), '\t' (horizontal 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 that is a member of a directly enclosing class declaration. If abstract public 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 '\u0000' to '\uffff' 0 are negative and the minimum value is zero. The maximum to 65535 value is 216 - 1. The positive infinity of type float is promoted to the positive Prints: 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 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 nonNone of the above private mutator methods, then the class can be called immutable.

2

e

3

a g

4

b d

5

f

6

c

7

e

8

b notify notifyAll c wait i

Page : 1

Dan Chisholm

No.

9

a

10 a 11 d

12 c

a b 13 c d e

Exam 9

Answers

Answers: Certified Java Programmer Mock Exam 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 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. 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 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 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. doubleValue floatValue intValue longValue parseDouble

14 f Prints: BbB

The Boolean.valueOf method returns a Boolean instance. The Boolean.booleanValue method returns a primitive. The Boolean.TRUE field is a reference to an instance of type Boolean that wraps the primitive value true.

15 b Prints: ffF 16 c Set

The Map interface organizes entries as key/value pairs. A list generally allows duplicate entries. A Set rejects duplicate entries.

Page : 2

Dan Chisholm

No.

17 e

b 18 c d

19 c

20 c

21 a

22 b

Exam 9

Answers

Answers: Certified Java Programmer Mock Exam 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. 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 the hashCode contract. The hashCode methods of classes B B C D and C will always return the same value during an execution 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 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. 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 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*$" Prints: GFC203 The type of the argument is null and could be converted to

Page : 3

Dan Chisholm

No.

23 f

24 e

25 a

26 b

27 c

28 f

Exam 9

Answers

Answers: Certified Java Programmer Mock Exam 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 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 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 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 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)). 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. 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

Related Documents

Main Exam 9 Answers
November 2019 31
Exam 9 Answers
October 2019 23
Exam 10 Answers
October 2019 24
Main Exam 3 Answers
November 2019 26
Exam 6 Answers
October 2019 21
Exam 7 Answers
October 2019 21