Today, I’m going to review my online test, chapter 3 of Oracle Certified Associate (OCA), provided by SYBEX. If you need to access to this online resources, you need to buy their book first. See https://sybextestbanks.wiley.com/.
Question 4
What is the result of the following code?
abbaaccc
abbaccca
bbaaaccc
bbaaccca
- An exception is thrown.
- The code does not compile.
The answer is B. At the beginning, the string is empty. Then, threes
characters had been appended into the char array, so the array contained three
a
characters. After that, two b
had been added into the char array at index
1, and the remaining characters were shifted. Same idea for adding ccc
.
Question 14
Which of the following can replace the comment to print "avaJ"
? (Choose all
that apply)
puzzle.reverse();
puzzle.append("vaJ$").substring(0, 4);
puzzle.append("vaJ$").delete(0, 3).deleteCharAt(puzzle.length - 1);
puzzle.append("vaJ$").delete(0, 3).deleteCharAt(puzzle.length);
- None of the above.
The answer is AC. In this example, the choice A is correct because the
method reverse
reverses the characters sequence stored inside the string
builder. The answer B is wrong because of 2 points: the returned substring is
wrong, and StringBuilder#substring
returns a string but not a string builder,
so even if the result is right, it must be retrieved immediately from return
statement. Answer C is correct since JavavaJ$
can be transformed into avaJ
by removing the first three characters and the last character.
Question 27
What is the result of the following?
A
B
C
- An exception is thrown.
- The code does not compile.
The answer is B. Because list one and list two are equal by value, but they are not equal by reference.
Question 31
What is the output of the following code?
2018 APRIL 2
2018 APRIL 30
2018 MAY 2
2021 APRIL 2
2021 APRIL 30
2021 MAY 2
- A runtime exception is thrown.
The answer is B. Local date is an immutable object, so any modification of such object creates a new date object. Since there’s no code retrieving the returned value, the returned value is ignored. Therefore, option B is correct.
Question 32
What is the output of the following code?
3/7/14 11:22 AM
5/10/15 11:22 AM
3/7/14
5/10/15
11:22 AM
- The code does not compile.
- A runtime exception is thrown.
The answer is E. Even though d
has both date and time. the formatter only
outputs time.
Question 33
What is the output of the following code?
5/9/13 11:22 AM
5/10/13 11:22 AM
5/9/14
5/10/14
11:22 AM
- The code does not compile.
- A runtime exception is thrown.
The answer is B. Period does not allow chaining. Only the last Period
method called counts, so only the two years are subtracted.