but static block has to be executed first then why x cant assign it's value as 5?
The concept here to understand is of variable scope.
Within the static block you are declaring and initializing a block scoped variable. Hence from the method main only the int primitive declared after the static block is visible as it's scope is wider than a block variable.
Thus the variables within static block and outside static block are two different variables and not the same.
can't we declare and initialize(both) in the static block?
Yes you can declare and initialize only non-static variables in a static block but then that would make it a block scoped variable.
If you wanted to initialize the int primitive declared outside the static block from within the static block then you could have used forward referencing and said:
[ November 23, 2008: Message edited by: Harvinder Thakur ]