Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java OCA/OCP 8 Programmer Practice Tests: Chapter 3, Question 36 (Errata?)  RSS feed

 
Nurettin Armutcu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nurettin Armutcu
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There seems to be a little mistake in Chapter 6, Question 8:

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.
 
Nurettin Armutcu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is one more in Chapter 6, Question 36:
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.
 
Nurettin Armutcu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chapter 7, Question 14:
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.
 
Nurettin Armutcu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chapter 7, Question 48:
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.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37384
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37384
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37384
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nurettin Armutcu wrote:There is one more in Chapter 6, Question 36:/quote]
That was already in the errata. It was original reported here
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37384
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37384
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!