Turn from: http://developer.51cto.com/art/200906/128274.htm, thank you
Initialization
1. Dynamic initialization: The array definition is performed separately from the assignment of the space and assignment to a set of values;
2. Static initialization: Allocates space and assigns values to the array elements while defining the numbers;
3. Default initialization: An array is a reference type and its elements are equivalent to the member variables of the class, so after the array allocates space, each element is also initialized by the hermit according to the rules of the member variable.
Instance:
Testd.java (Dynamic):
Program code:
- Public class TestD
- {
- public static void Main (String args[]) {
- int a[];
- A = new int[3];
- a[0] = 0;
- a[1] = 1;
- a[2] = 2;
- Date days[];
- Days = new date[3];
- days[0] = new Date (4,5);
- days[1] = new Date (2,31);
- days[2] = new Date (4,4);
- }
- }
- Class Date
- {
- int year,month,day;
- Date (int year,int. month,int day) {
- this.year = year;
- this.month = month;
- this.day = day;
- }
- }
Tests.java (Static):
Program code:
- Public class TestS
- {
- public static void Main (String args[]) {
- int a[] = {0,1,2};
- Time times [] = {New Time (1, +), New Time (5,3, 2)};
- }
- }
- Class time
- {
- int hour,min,sec;
- Time (int hour,int min,int sec) {
- this.hour = hour;
- this.min = min;
- this.sec = sec;
- }
- }
Testdefault.java (default):
Program code:
- Public class Testdefault
- {
- public static void Main (String args[]) {
- int a [] = new int [5];
- System.out.println ("" + a[3]);
- }
- }
(go) deep learning of Java two-dimensional arrays (static vs. dynamic)