Post

@EclipseJavaIDE 1. Variable x1 is initialised (x1= 2)
2. The 1st Static block is executed (x1=3)
3. The 2nd static block is executed (x1 = 1)
Final value of x1 = 1
English

@EclipseJavaIDE Output
1
as x1 = 2, then after x1++ 3, and finally x1 -=2 will make it 1 ( 3-2 )
English

@EclipseJavaIDE 1, static initializer and block before main()
Pune, India 🇮🇳 English

@EclipseJavaIDE @java I feel like as a student during the exam times when i read this kind of tweets 😂😂
English

@EclipseJavaIDE @java 1) static field x1 initialized with 2
2) first static block is executed x1++, so x1 is 3
3) next static block is executed x1-=2, so x1 is 1
4) main-Method is executed so 1 is printed out
Seeing multiple static blocks in production code is one of the wtf moments in review.
English

@EclipseJavaIDE @java I just kill the writer of those lines of code... ^^
English

@EclipseJavaIDE @java Hey you're resetting the values ..lol
As I saw suddenly I thought that it must be 3 but still due to the static block this has been initialised earlier and hence it gave 2.....😊😊
English

@EclipseJavaIDE @java I'm surprised at the number of people who don't like a puzzle! Career change time?
English

@EclipseJavaIDE @java While class loading the SIB load first from top to bottom, in first static block x1 is having post increment and it will increment x1 by 1 for next usage.
In second static block x1 = x1 - 2 is x1 = 3 - 2 become 1
So final value of x1 = 1
English

@EclipseJavaIDE @java 1. Initially x1 will be assigned with value 2.
2. First static block will increment value with 1 (x1=3).
3. Second static block will decrement x1 by 2 (x1=1).
4. Main method will print value of x1 as 1.
English

@EclipseJavaIDE @EclipseFdn Variable initiée,
Variable ++,
Variable -= 2,
Print
Français






















