Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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

 
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.
 
author & internet detective
Posts: 40359
819
Eclipse IDE VI Editor Java
  • 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
Posts: 40359
819
Eclipse IDE VI Editor Java
  • 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
Posts: 40359
819
Eclipse IDE VI Editor Java
  • 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
Posts: 40359
819
Eclipse IDE VI Editor Java
  • 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
Posts: 40359
819
Eclipse IDE VI Editor Java
  • 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!
 
Greenhorn
Posts: 9
  • 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.



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.
 
Rancher
Posts: 261
12
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeff,

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.
 
Jeff Stam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Brecht,

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
 
Jeanne Boyarsky
author & internet detective
Posts: 40359
819
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff,
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!
 
Forget Steve. Look at this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic