Win a copy of Svelte and Sapper in Action this week in the JavaScript 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Possible Error in OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 9 in the review questions for Chapter 3 of the OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide contains the following code for evaluation:



The answer to Question 9 in the appendix says, "The code compiles without issue, so option G is incorrect." But when I try to compile it, the code does not compile. Here's my class that contains the code:



And here's what the compiler tells me:

C:\java-11-certification>javac QuestionNine.java
QuestionNine.java:6: error: illegal start of expression
               System.out.println( a > 2 ? --c : b + +);
                                                      ^
QuestionNine.java:7: error: ')' expected
               System.out.println( b = (a! = c ? a : b + +));
                                         ^
QuestionNine.java:7: error: illegal start of expression
               System.out.println( b = (a! = c ? a : b + +));
                                                          ^
QuestionNine.java:7: error: not a statement
               System.out.println( b = (a! = c ? a : b + +));
                                               ^
4 errors

So is Option G actually correct? Or am I missing something?

Thanks!

Richard

P.S. Please excuse me if someone has already pointed this out. I took a quick look around but did not see anything about this.

 
Richard Schetnan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought maybe the extra spaces in the increment operators may have been causing the problems, but after getting rid of the spaces, compilation still fails, albeit with different messages from the compiler. I now get three errors instead of four.
 
Marshal
Posts: 70266
282
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have copied the code incorrectly. The operators are  ++ and != without the spaces. Don't insert spaces after ( or between ++ or -- and their operands. I tried the code and it compiled without error, once I got rid of the extraneous spaces.
 
Richard Schetnan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell. I copied the code over from my Kindle edition and failed to notice all of the extra spaces. I'll be more careful about that.
 
Campbell Ritchie
Marshal
Posts: 70266
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check the Kindle edition carefully in case those spaces have been added in printing.
 
Hang a left on main. Then read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic