Post

🌒 Eclipse Java IDE
🌒 Eclipse Java IDE@EclipseJavaIDE·
What happens if I try to run this program? (only try after committing your answer ;)
🌒 Eclipse Java IDE tweet media
English
72
36
172
0
Ali Özcan
Ali Özcan@alioezcan87·
@EclipseJavaIDE @java I feel like as a student during the exam times when i read this kind of tweets 😂😂
English
0
0
1
0
Khan
Khan@Khan28570886·
@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
0
0
1
0
Amit
Amit@Amit58849996·
@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
0
0
0
0
Vinit Jordan
Vinit Jordan@VinitJordan·
@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
0
0
0
0
Gayatri Pawar
Gayatri Pawar@Gayatri_S_Pawar·
@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
0
0
0
0
Paylaş