• Post Reply Bookmark Topic Watch Topic
  • New Topic

Code block  RSS feed

 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code: Everything is fine. There is an other code: The first code uses a code block and the second code does not use a code block. In what way is there a difference?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think is the difference? Is this from a book or something? If so, please cite your source.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or write some code to find out what the difference (if any) is.
 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is my own code. I think there is no big difference; it is the same. Nevertheless there is a difference. One Statement is in a code block, the other statement is not. Maybe there is a difference when initialsiation happens?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming this code even compiles, where would it be located in the context of a class? That is, is that code going to be inside a method or outside? What are you trying to understand here in terms of learning goals? I assume this is in preparation for the exam since that's what you appear to be doing in your other posts.
 
Paul Clapham
Sheriff
Posts: 22839
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Urs Waefler wrote:Maybe there is a difference when initialsiation happens?


It's possible that your first case is an example of an instance initializer. Or maybe not, depending on whether the code block is right after the declaration. On the other hand in your second case, if the two lines are exactly as shown then they won't compile because outside a method you can only have declarations, methods, constructors, and initializers. Not statements.
 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. That is what I was looking for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!