• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Sybex CSG 11 - report an error

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I have noticed an error in the CSG 11 book. On page 317, the last example
line 2 doesn't compile not line 4
 
Marshal
Posts: 78698
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please supply more details about the book.
It is a convention in cert exam books that they assume fields and imports have been declared before the code blocks. In which case that code might compile after all.
 
Master Rancher
Posts: 4661
63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, that's not the issue.  The only way that code could compile is if we assume an additional static initializer block.  Otherwise the final field "type" is not initialized.  That's the problem at line 2.

Also, the field "volume" has never been declared - that one could be solved by assuming an unseen field declaration for "volume".  But frankly, that seems a stretch too.  Exam code may omit imports, sure... but field declarations?  That seems a bridge too far, I think.

To be fair, it's possible that different compilers report the location of the error differently.  Because the problem is really a combination of line 2, declaring an unassigned final variable, and line 5 or 6, reaching the end of a constructor without anyone having set the value for that final variable.  Plus the fact that line 5 mentions a different variable, undeclared.
 
Campbell Ritchie
Marshal
Posts: 78698
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:No, that's not the issue. . . .

Yes, I was mistaken there. I haven't checked any errata to see whether this is a newly found error

an additional static initializer block. . . .

Instance initialiser, surely?
 
Mike Simmons
Master Rancher
Posts: 4661
63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, slip of the keyboard there.
 
author & internet detective
Posts: 41775
887
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the actual example in the book. Which does contain the instance initializer mentioned.


And the compiler errors I get are


Technically the compiler errors are on this.volume = 2; and the line after (vs before.) But it definitely isn't on private final String type;
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic