Uninitialized arrays

0

After the declaration

int[ ] a;

What is stored in the a variable? null or an undefined value, where a can not be used until something is assigned to it?

    
asked by anonymous 01.12.2017 / 04:04

1 answer

1

It depends on where that statement was made. If it is an attribute the value will be null. Attributes in java are given a default value of initialization. Every attribute that type is a class will be initialized to null. Primitive types will be initialized with a default value that is set by java, eg variables of type int will be initialized with 0.

However, if this statement is performed in a method, then the variable will be in an uninitialized state. If you try to use the variable then the compiler will complain that the variable was not initialized.

    
01.12.2017 / 04:43