PASS - TAKER : Anonymos

Java 7 - OCA 5 Working with Strings- Arrays- and ArrayLists

Correct : 2

16% Complete (success)

16 %

False : 10

83% Complete (success)

83 %



Anonymos 2019-11-26T08:34:30

Not Correct

Given: {code} Which two substrings will be included in the result? (Choose two.)

The String operations are working on a new (lost) String not String s. The StringBuilder operations work from left to right.

Not Correct

Given: {code} And, if the code compiles, the command line: java Hilltop eyra vafi draumur kara What is the result?

The horses array's first four elements contain Strings, but the fifth is null, so the toUpperCase() invocation for the fifth element throws a NullPointerException.

Not Correct

Given: {code} What is the result?

The Unicode declaration must be enclosed in single quotes: '\u004e'. If this were done, the answer would be A, but knowing that equality isn't on the OCA exam.

Correct

Given: {code} What is the result? (Choose all that apply.)

A ClassCastException is thrown at line 7 because o1 refers to an int[][], not an int[]. If line 7 were removed, the output would be 4.

Not Correct

Given: {code} What is the result?

ArrayList elements are automatically inserted in the order of entry; they are not automatically sorted. ArrayLists use zero-based indexes and the last add() inserts a new element and shifts the remaining elements back.

Not Correct

Given: {code} Which two are true about the objects created within main(), and which are eligible for garbage collection when line 14 is reached?

da refers to an object of type "Dozens array" and each Dozens object that is created comes with its own "int array" object. When line 14 is reached, only the second Dozens object (and its "int array" object) are not reachable.

Not Correct

Given: {code} What is the result?

A two-dimensional array is an "array of arrays." The length of ba is 2 because it contains two, one-dimensional arrays. Array indexes are zero-based, so ba[1] refers to ba's second array.

Not Correct

Given: {code} Which are true? (Choose all that apply.)

Although String objects are immutable, references to Strings are mutable. The code s1 += "d"; creates a new String object. StringBuilder objects are mutable, so the append() is changing the single StringBuilder object to which both StringBuilder references refer.

Not Correct

Given: {code} If the garbage collector does NOT run while this code is executing, approximately how many objects will exist in memory when the loop is done?

StringBuilders are mutable, so all of the append() invocations are acting upon the same StringBuilder object over and over. Strings, however, are immutable, so every String concatenation operation results in a new String object. Also, the string " " is created once and reused in every loop iteration.

Correct

Given: {code} What is the result?

Although main()'s b1 is a different reference variable than go()'s b1, they refer to the same Box object.

Not Correct

Given: {code} What is the result?

The substring() invocation uses a zero-based index and the second argument is exclusive, so the character at index 8 is NOT included. The toUpperCase() invocation makes a new String object that is instantly lost. The toUpperCase() invocation does NOT affect the String referred to by s.

Not Correct

Given: {code} Which lines of code (if any) break encapsulation? (Choose all that apply.)

When encapsulating a mutable object like an ArrayList, your getter must return a reference to a copy of the object, not just the reference to the original object.