Instance initializer


Source code

1class InstanceInitializer {
2
3 int x = 100;
4
5 int z;
6
7 InstanceInitializer(String str) {
8 this.x = Integer.parseInt(str);
9 }
10
11 InstanceInitializer() {
12 }
13
14 {x = 30;}
15}
16

Bytecode


Comment

Initialization of instance fields is performed in body of each contructor. If there are several constructors - initialization code is duplicated.

Java compiler version: 21
Other examples
Main page