This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

intiliazation blocks

 
Chetan Dodiya
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Tarsier{
static String s="-";
public static void main(String [] args){
go();
System.out.println(s);
}
{go();}
static{go();}
static void go(){s+="s";}
}


the answer is "-ss"
but why "-sss"
why the {go();} is not executeg???
 
M Srilatha
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please quote the source from where you got the question!

{go();} is not executed because its a instance initialization block.
In the main() method, no object of the class is created. So this block doesnt execute. Add Tarsier t = new Tarsier(); to the main() method. Then it will execute!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic