扫码关注官方订阅号
如题:
int[] arr = new int[3]; int[][] arr = new int[2][3]; Integer[] arr = new Integer[3]; Integer[][] arr = new Integer[2][3]; 以上语句分别会产生多少个对象?
学习是最好的投资!
new 了几次就是几个
javapublic class ArrayListDemo { public static void main(String[] args) { int[] arr1 = new int[3]; int[][] arr2 = new int[2][3]; Integer[] arr3= new Integer[3]; Integer[][] arr4 = new Integer[2][3]; if(arr1 instanceof Object){ System.out.println("true"); } if(arr2 instanceof Object){ System.out.println("true"); } if(arr3 instanceof Object){ System.out.println("true"); } if(arr4 instanceof Object){ System.out.println("true"); } } }
java
public class ArrayListDemo { public static void main(String[] args) { int[] arr1 = new int[3]; int[][] arr2 = new int[2][3]; Integer[] arr3= new Integer[3]; Integer[][] arr4 = new Integer[2][3]; if(arr1 instanceof Object){ System.out.println("true"); } if(arr2 instanceof Object){ System.out.println("true"); } if(arr3 instanceof Object){ System.out.println("true"); } if(arr4 instanceof Object){ System.out.println("true"); } } }
全部打印出true。说明在java中间,数组就是一个Obejct对象。
每个语句都会将 arr 变量指向一个新创建的对象。
PHP学习
技术支持
返回顶部
new 了几次就是几个
全部打印出true。说明在java中间,数组就是一个Obejct对象。
每个语句都会将 arr 变量指向一个新创建的对象。
