Initialize variable

Initialize Member Variables(Class variable, Instance variable)

Initializing order

  1. cv

  2. iv

  1. automatic : 0

  2. =

  3. {} : 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 =

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 {...}

3. initialize (instance) with constructor

Last updated

Was this helpful?