基本数据类型必须先初始化 必须赋值
引用数据类型在定义时必须初始化 可以不赋值,会有默认值
开辟空间会直接会有默认值 对一维数组而言
对二维数组和对象数组,仅仅开辟了地址空间
public class cushihua {
public static void main(String[] args) {
int a;
// System.out.println(a);// 报错未初始化变量
a=0;
System.out.println(a);
//对象也会直接初始化
student xiao= new student();
student xiao;//为初始化
System.out.println(xiao);
//int [] b=new int [2];
//数组同对象
int[] b;
System.out.println(b);
Car[] car111 = new Car[3];//这里是声明只开辟了空间 注意未进行初始化
car111[0]=car;
car111[1]=new Car("特斯拉007","特斯拉",300000);
//赋值了两个数组对象,第三个为空,没有默认值,会报错空指针
for(Car c:car111){//for加强循环数组遍历
System.out.println("名字" + c.name + "品牌" + c.brand + "价格" + c.price);
}
int [] a= new int[4];//已进行初始化
String[] v= new String[4];//已进行初始化
a[1]=1;
v[1]="223";
for(int i:a){
System.out.println(i);
}
for(String c:v){
System.out.println(c);
}
int[][] e=new int[3][];
System.out.println(e);//地址[[I@1b6d3586
System.out.println(e[1]);//null
//System.out.println(e[1][0]); //报错空指针
}
}