• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about enums and enhanced for

 
Ranch Hand
Posts: 36
Firefox Browser Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I have the following code:



My first question is: does it matter that the statement is written after the constructor of the enum?
Second question: does the enhanced for automatically put "\n" after the end of each Sop ?

Thank you,
Mihai
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Mihai Lita wrote:My first question is: does it matter that the statement is written after the constructor of the enum?


No it doesn't matter, you can declare an variable after using it,

Mihai Lita wrote:Second question: does the enhanced for automatically put "\n" after the end of each Sop ?


No, but it will allways go to the next line:
Terminate the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').
http://download.oracle.com/javase/1.3/docs/api/java/io/PrintStream.html#println%28%29
 
Mihai Lita
Ranch Hand
Posts: 36
Firefox Browser Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,
I was right in my face but coudln`t see the println!
 
Marshal
Posts: 79254
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Loic Beylot
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome... and thanks
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mihai, when you copy code from a book or some other source, please mention where you copied it from (QuoteYourSources). Isn't this from Head First Java? (I vaguely recognise it...).
 
Mihai Lita
Ranch Hand
Posts: 36
Firefox Browser Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it`s from KB SCJP exam.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, the SCJP Study Guide, also called "K&B" after the names of the authors (Kathy Sierra and Bert Bates).

Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic