Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - In the constructor of java class: how to initialize the array
In the constructor of java class: how to initialize the array
1, java constructor -array initializes the array in the constructor, such as the public class array {private int [] [] matrix; public array(int r,int c){ matrix = new matrix[r][c]; } }

Matrix = new matrix [r] [c];

2. here is new int [] []; The eight basic data types in java have default values, and the default value of int is 0.

3, so the default value in the array is 0.

4. But remember that variables with default values must be attributes of classes, and local variables in methods must be assigned values before they can be used.