> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/java/initialize-variable.md).

# Initialize variable

**Initialize Member Variables**(Class variable, Instance variable)

Initializing order

1. cv

2. iv

3. automatic : 0

4. \=

5. {} : class variable(static) => static {...}, instance variable => constructor

Initialize local variable before use!(ESSENTIAL)

member variable(instance variable, class(static) variable)) is initialized automatically.

1. Initialize with =

```java
class Car {

    int door = 4;
    //Engine e;
    Engine e = new Engine();//create object and put into e 
    
```

2\. initialize with {..}

initialize instance : {...}

**initialize cv(classs variable(static))** : **static** {...}

```java
class StaticBlockTest {
    static int[] arr = new int[10];
    //initialize static variable(class variable)
    static {
        for(int i = 0; i < arr.length;i++) {
            arr[i] = (int)(Math.random()*10)+1;
        }
    }
}
```

3\. **initialize (instance) with constructor**

```java
class Car {
    Car(String color, String gearType, int door) {
        this.color = color;
        this.gearType = gearType;
        this.door = door;
    }
...
}
```
