Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Java variables are not initialized after declaration.
Java variables are not initialized after declaration.
When defining a variable, JAVA always gives it a default value.

Default value corresponding to data type

Byte): 0

Short (short integer): 0

Int (integer): 0

Length (long molding): 0L

Folic acid (floating-point): 0.0f

Double (double precision): 0.0b

Char (character type):' \u000'

Boolean value: false

String (string type): null

But if you program, you will get an error when you define a data type and write it in a main method.

For example:

Public category a7 {

Public static void main(String[] args) {

int a;

system . out . println(a); //An error was reported.

}

}

But if you write it in two classes or in one class, if you modify the type with static, you won't get an error.

For example:

Public category a7 {

Static int a;; //This is modified in a static way.

Public static void main(String[] args) {

system . out . println(a);

}

}

The output result is 0.