• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about enums and enhanced for

 
Mihai Lita
Ranch Hand
Posts: 36
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • 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
 
Loic Beylot
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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 Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
I was right in my face but coudln`t see the println!
 
Campbell Ritchie
Sheriff
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Loic Beylot
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome... and thanks
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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 Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it`s from KB SCJP exam.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic