🔞 ADULT: T//certification/Java OCA OCP Programmer Practice - High Quality
- Post Reply Bookmark Topic Watch Topic
- New Topic
- Devaka Cooray
- Campbell Ritchie
- Tim Cooke
- Ron McLeod
- Paul Clapham
- Liutauras Vilda
- Jeanne Boyarsky
- paul wheaton
- Tim Holloway
Java OCA/OCP 8 Programmer Practice Tests: Chapter 3, Question 36 (Errata?)
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
A. If one of the operands of ^ is true, then the result is always true.
B. There is a conditional form of the operator, denoted as ^^.
C. If both operands of ^ are true, the result is true.
D. The ^ operator can only be applied to boolean values.
Option D is said to be correct: Finally, Option D is correct as the ^ is only applied to boolean values in Java.
But there is a bitwise ^ operator in Java too, so it can be applied to both boolean and numerical values.
-
1
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
8. Which of the following can fill in the blank to make the class compile?
A. Public int
B. Long
C. void
D. private String
Option B is said to be correct: Option B is correct and has package-private access. It also uses a return type of Long that the integer value of 10 can be easily assigned to without an explicit cast.
This sample code would work with a primitive long as return type, but the wrapper class Long requires an explicit cast before returning.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
How many lines of code would need to be removed for the following class to compile?
A. One
B. Two
C. Three
D. The code will not compile regardless of the number of lines removed.
For Option C, it is said: [...] Finally, the declaration of thursday does not compile because the final modifier cannot appear before the access modifier. For these reasons, Option C is the correct answer.
Final modifier may appear before the access modifier, so the correct answer should be Option B.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What is the output of the following application?
A. Walking and running!
B. Walking and jogging!
C. Sprinting!
D. The code does not compile.
Answer: C. Having one class implement two interfaces that both define the same default method signature leads to a compiler error, unless the class overrides the default method. In this case, the Sprint class does override the walk() method correctly, therefore the code compiles without issue, and Option C is correct.
This would be correct as output, but the application does not run since there is no String[] parameter defined in the parameter list.
-
1
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Given that Integer and Long are subclasses of Number, what type can be used to fill in the blank in the class below to allow it to compile?
A. Long
B. Integer
C. Long or Integer
D. Long or Number
Answer: [...] For these reasons, Long is the only class that allows the code to compile, making Option A the correct answer.
Option A would be correct if 12L is returned instead of 12. Whe have the same mistake as in Chapter 6, Question 8.
-
1
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Nurettin Armutcu wrote:Option D is said to be correct: Finally, Option D is correct as the ^ is only applied to boolean values in Java.
But there is a bitwise ^ operator in Java too, so it can be applied to both boolean and numerical values.
There is. It's out of scope of the OCA and OCP exams. So you are correct that extra knowledge makes it true. The good thing is that this book is like the exam and tells you how many are correct. The bad thing is that doesn't help here.
So you are right, that this question as a problem. I've noted this in the errata.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Nurettin Armutcu wrote:There seems to be a little mistake in Chapter 6, Question 8:
...
This sample code would work with a primitive long as return type, but the wrapper class Long requires an explicit cast before returning.
Agreed and I've added this to the errata
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Nurettin Armutcu wrote:There is one more in Chapter 6, Question 36:/quote]
That was already in the errata. It was original reported here
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Nurettin Armutcu wrote:Chapter 7, Question 14:
...
This would be correct as output, but the application does not run since there is no String[] parameter defined in the parameter list.
Agreed and I've added it to the errata.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Nurettin Armutcu wrote:Chapter 7, Question 48:
...
Option A would be correct if 12L is returned instead of 12. Whe have the same mistake as in Chapter 6, Question 8.
This one is in the errata. I caught it right after the book printed. My fix is having it be "return null;" instead.
Thanks for all the comments!
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
36. What statement about the ^ operator is correct?
A. If one of the operands of ^ is true, then the result is always true.
B. There is a conditional form of the operator, denoted as ^^.
C. If both operands of ^ are true, the result is true.
D. The ^ operator can only be applied to boolean values.
Option D is said to be correct: Finally, Option D is correct as the ^ is only applied to boolean values in Java.
But there is a bitwise ^ operator in Java too, so it can be applied to both boolean and numerical values.
Errata says: Option D is incorrect if you have extra knowledge. So you give yourself credit if you wanted to choose “none of the above”
None of the above?
In my opinion A is the correct answer. Right?
Please help me explain.
Thanks.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Have a look here at what is mentioned in the JLS: "For ^, the result value is true if the operand values are different; otherwise, the result is false."
In case of answer A, let's say first operand is true but the second one as well, then the result will be false.
Oracle Certified Professional Java SE 8
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If one of the operands of ^ is true, then the result is always true.
So assuming, that if one of the operands is true the other is false, is wrong?
https://www.baeldung.com/java-xor-operator
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Welcome to CodeRanch!
This threadwas the initial errata report. The key point is that bitwise operators work differently than logical ones. Luckily, bitwise operators aren't on the exam!
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
Bookmark Topic
Watch Topic
- New Topic












