Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can init block be declared between a couple of methods?

 
Shanu Pandey
Greenhorn
Posts: 18
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can init block be declared between a couple of methods?if yes,then how.Please Give code...
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're asking for a code example for that question? Really? When you could have spent 30 seconds producing an example to ask about? Come on. Show us an example. And tell us what happened when you compiled it and what your question is about that.
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Initialization blocks can be put any place in the java code file. The compiler will sort it out.

However, the Java Coding Convention has an opinion on where to put them. Static initialization blocks first, then instance initialization blocks. After that comes the constructors and then the rest.

See http://blog.sanaulla.info/2008/05/01/initialisation-blocks-in-java/ for a good article about Initialisation blocks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic