aspose file tools*
The moose likes Beginning Java and the fly likes Question about enums and enhanced for Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about enums and enhanced for" Watch "Question about enums and enhanced for" New topic
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: 40052
    
  28
. . . and welcome to the Ranch
Loic Beylot
Greenhorn

Joined: Mar 24, 2011
Posts: 8
You are welcome... and thanks
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

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 8 API documentation
Mihai Lita
Ranch Hand

Joined: Jan 11, 2011
Posts: 36

it`s from KB SCJP exam.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

Ah, the SCJP Study Guide, also called "K&B" after the names of the authors (Kathy Sierra and Bert Bates).

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about enums and enhanced for