The second Line of code, why we put i=5; between {}? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The second Line of code, why we put i=5; between {}?

Public class prog{ Static { i=5;} Static int i; Public static void main (String[] args){ System.out.println(i); } }

12th Feb 2020, 3:55 PM
Hichem GOUIA
Hichem GOUIA - avatar
3 Answers
+ 2
Hichem GOUIA That's call as static block where you can initialize multiple variable.
12th Feb 2020, 4:32 PM
A͢J
A͢J - avatar
+ 1
You could have just wrote- static int i = 5; But you have initialized it through a static block. Both means the same.
12th Feb 2020, 4:19 PM
Avinesh
Avinesh - avatar
+ 1
Thanks my Friends😊
12th Feb 2020, 4:50 PM
Hichem GOUIA
Hichem GOUIA - avatar