1. Initialization of the data members of the class

When a data member is defined in a class, it is automatically assigned an initial value:

The data type The initial value
byte 0
short 0
int 0
long 0L
float 0F
double 0
boolean false
char ‘\ u0000’
All reference data types null

2. Initialization of local variables

When you define a local variable in a function, because Java is a strongly typed language, local variables in Java must be initialized before use, otherwise the system will report an error.

Such as:

class Test
{
    public static void main(String[] args) 
    {
        int i;

        System.out.printf("i = %d.\n",i); }}Copy the code

Because the variable I was used without being initialized, Java reported an error:



To receive more exciting articles and resources, please subscribe to my wechat official account: “McUlover666”.