| Author |
Question about enums and enhanced for
|
Mihai Lita
Ranch Hand
Joined: Jan 11, 2011
Posts: 36
|
|
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
Joined: Mar 24, 2011
Posts: 8
|
|
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
Joined: Jan 11, 2011
Posts: 36
|
|
Thanks,
I was right in my face but coudln`t see the println!
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
. . . and welcome to the Ranch
|
 |
Loic Beylot
Greenhorn
Joined: Mar 24, 2011
Posts: 8
|
|
You are welcome... and thanks
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12952
|
|
|
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...).
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Mihai Lita
Ranch Hand
Joined: Jan 11, 2011
Posts: 36
|
|
|
it`s from KB SCJP exam.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12952
|
|
Ah, the SCJP Study Guide, also called "K&B" after the names of the authors (Kathy Sierra and Bert Bates).
Thanks.
|
 |
 |
|
|
subject: Question about enums and enhanced for
|
|
|