donaricano-btn

 Instance initializer block


- It used to initialize the instance data member

- It run each time when object of the class is created

- The initialization of the instance variable can be directly but there can be performed extra operations while initializing the instance variable it the instance initializer block


1. Why use instance initializer block?

- Suppose I have to perform some operations while assigning value to instance data member


2. Example


3. What is invoked first, instance initializer block or constructor?

1) How to work

- It seems that instance initializer block is firstly invoked but NO

- The java compiler copies the instance initializer block in the constructor after the first statement super()

- constructor is invoked firstly

4. Rules for instance initiallizer block

1) The instance initializer block is created when instance of the class is created

2) It is invoked after the parent class constructor is invoked

3) It comes in the order in which they appear


'Back-End > Java_1' 카테고리의 다른 글

[Java] Runtime Polymorphism  (0) 2016.09.08
[Java] Final keyword  (0) 2016.09.07
[Java] Super keyword  (0) 2016.08.25
[Java] Covariant Return type  (0) 2016.08.24
[Java] Overloading vs Overriding  (0) 2016.08.24
블로그 이미지

리딩리드

,