Java 数组

关键字:JAVA 数组
1,首先数组在JAVA中也是一个类。


2,本来类型中的继承关系,在相应的数组中同样保持。
3,注意Object[]并不是所以数组类型的基类,因为int是基本数据类型,它不是从Object类派生出来的。
例子:
public class Tstss {
	public static void main(String[] args) {
		System.out.println("------------------ Start\n");
		
		D1_0 d0 = new D1_0();
		D1_1 d1 = new D1_1();
		D1_2 d2 = new D1_2();
		System.out.println("Objcet D1_0 D1_1 D1_2");
		System.out.println((d0 instanceof Object) +" "+ (d0 instanceof D1_0) +
				" "+ (d0 instanceof D1_1) +" "+ (d0 instanceof D1_2));
		d0 = d1;
		System.out.println((d0 instanceof Object) +" "+ (d0 instanceof D1_0) +
				" "+ (d0 instanceof D1_1) +" "+ (d0 instanceof D1_2));
		d0 = d2;
		System.out.println((d0 instanceof Object) +" "+ (d0 instanceof D1_0) +
				" "+ (d0 instanceof D1_1) +" "+ (d0 instanceof D1_2));
		
		D1_0[] d0A = new D1_0[0];
		D1_1[] d1A = new D1_1[0];
		D1_2[] d2A = new D1_2[0];
		
		System.out.println("------------------ ");
		System.out.println("Objcet object[] D1_0[] D1_1[] D1_2[]");
		System.out.println((d0 instanceof Object)+" "+ (d0A instanceof Object[]) 
				+" "+ (d0A instanceof D1_0[]) +	" "+ (d0A instanceof D1_1[]) +" "+ (d0A instanceof D1_2[]));
		d0A = d1A;
		System.out.println((d0 instanceof Object)+" "+ (d0A instanceof Object[]) 
				+" "+ (d0A instanceof D1_0[]) +	" "+ (d0A instanceof D1_1[]) +" "+ (d0A instanceof D1_2[]));
		d0A = d2A;
		System.out.println((d0 instanceof Object)+" "+ (d0A instanceof Object[]) 
				+" "+ (d0A instanceof D1_0[]) +	" "+ (d0A instanceof D1_1[]) +" "+ (d0A instanceof D1_2[]));
				
		System.out.println("------------------ End");
	}
}
class D1_0 implements Serializable{
	private static final long serialVersionUID = -5747074459156767211L;
	private int d0;
}
class D1_1 extends D1_0 {
	private static final long serialVersionUID = -9091624871086037966L;
	private int d1;
}
class D1_2 extends D1_1 {
	private static final long serialVersionUID = -5704053473053777096L;
	private int d2;
}
 
写道
------------------ Start

Objcet D1_0 D1_1 D1_2
true true false false
true true true false
true true true true
------------------
Objcet object[] D1_0[] D1_1[] D1_2[]
true true true false false
true true true true false
true true true true true
------------------ End
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值