package test;
public class Test {
public static void main(String[] args) {
//声明
int a[];
//创建数组对象
a = new int[4];
//初始化(对数组元素的初始化)
//(1)默认初始化:数组元素相当于对象的成员变量,默认值跟成员变量相同
//(2)动态初始化、
for (int i = 0; i < a.length; i++) {
a[i] = i * 12;
}
//(3)静态初始化
int c[] = {23, 34, 35, 26}; //注意静态初始化,声明和初始化是在一起
Car cars[] = {
new Car("奔驰"),
new Car("比亚迪"),
new Car("宝马")
};
}
}
class Car {
public String name;
public Car(String name) {
this.name = name;
}
}