View RSS Feed

Java Array

Array Store Exception

Rate this Entry
by , 03-04-2012 at 10:18 AM (2892 Views)
If array variable v consists of type A[] (where A is a reference type) then v might hold a reference to any array type B[] instance.( provided that B could be assigned to A).

Java Code:
class Point { int x, y; }
class ColoredPoint extends Point { int color; }
class Test {
	public static void main(String[] args) {
		ColoredPoint[] cpa = new ColoredPoint[10];
		Point[] pa = cpa;
		System.out.println(pa[1] == null);
		try {
			pa[0] = new Point();
		} catch (ArrayStoreException e) {
produces the output:

Variable pa has type Point[].Variable cpa has its value a reference, to an object of type ColoredPoint[]. To a point, a ColoredPoint could be assigned; hence to pa, the value of cpa can be assigned.

Submit "Array Store Exception" to Facebook Submit "Array Store Exception" to Digg Submit "Array Store Exception" to Submit "Array Store Exception" to StumbleUpon Submit "Array Store Exception" to Google

Updated 03-04-2012 at 10:21 AM by Java Array