+ 3
what is the difference between these initializations? class A { private int i; { i = 67; } } and class A { private int i = 67; }
3 Answers
+ 6
The first one is an initializer block. The Java compiler will copy initializer blocks into every constructor. Therefore, this approach can be used to share a block of code between multiple constructors.
The second one is an initial value for a field in its declaration.
See more different ways of initializing field
https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html
0
Thanks a lot man đ
- 2
your first one you have i set as 67 and set as your variable. your second one you dont. you just have it say 67 and the computer will be "confused"