• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

error in kb6 book

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please refer page no. 62 of kb6 book . following is the paragraph copied from the book



here the authors have put semi-colon in the wrong place. according to me it should have been like this:


enum CoffeeSize { BIG, HUGE, OVERWHELMING ; } // note the semicolon

please confirm if i'm right ?
 
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:please refer page no. 62 of kb6 book . following is the paragraph copied from the book



here the authors have put semi-colon in the wrong place. according to me it should have been like this:


enum CoffeeSize { BIG, HUGE, OVERWHELMING ; } // note the semicolon

please confirm if i'm right ?



No that is correct, you can see many examples.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:
enum CoffeeSize { BIG, HUGE, OVERWHELMING ; } // note the semicolon



actually ; after the body declaration is optional


however ; after the field declaration is bit tricky if you are declaring methods after the instance variable then the instance(constants) declaration must end with ; else not required.
just remove the semicolon from above code and try putting method and listen the compiler.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

saloni jhanwar wrote:

gurpeet singh wrote:please refer page no. 62 of kb6 book . following is the paragraph copied from the book



here the authors have put semi-colon in the wrong place. according to me it should have been like this:


enum CoffeeSize { BIG, HUGE, OVERWHELMING ; } // note the semicolon

please confirm if i'm right ?



No that is correct, you can see many examples.



i'm not saying that it is wrong or compiler error putting semi colon at the end of curly braces. semi colon will work since it is an empty statement. what i'm asking is that further down the pages , specifically page no. 63 the book gives another example as follows :


here as you can see the semi-colon is placed after the enum constants .this is what i'm talking about. here in this case semi colon is required because there are more statements after the enum constants, whereas in earlier case it is optional . the main point is the location of the semi colon. i think that might be some typing error .
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As your initial code has, semicolon is optional if there is only one statement in the enum body. In that case it will the enum constants alone and no variables, constructors or methods, etc in enum body.

And semicolon is not needed at the end of enum braces.

Very slow today
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:the main point is the location of the semi colon. i think that might be some typing error .


Your point seems to be valid. The semicolon should have been placed after OVERWHELMING in your first post.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks guys. that is what i was talking about. this means there is typing error in the book. the semicolon in my first example had to be after the field declarations and NOT after the braces, then only it makes sense .
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh.. Yeah you are right. but co-incidentally semi colon after the brace also optional
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:thanks guys. that is what i was talking about. this means there is typing error in the book. the semicolon in my first example had to be after the field declarations and NOT after the braces, then only it makes sense .



Semicolon after enum constant fields don't make any sense if you don't declare methods, constructor and variables, while it is mandatory if you do so else it will make syntax error.
 
reply
    Bookmark Topic Watch Topic
  • New Topic