java - Compile Time & Run Time Error -
class dims { public static void main(string[] args) { int[][] = {{1,2,}, {3,4}}; int[] b = (int[]) a[1]; object o1 = a; int[][] a2 = (int[][]) o1; int[] b2 = (int[]) o1; // line 7 system.out.println(b[1]); } } i have doubt in above piece of code in java.
why give runtime exception , not compile time error @ line number 7?
because o1 int[][], not int[]. runtimeexception classcastexception, because first array of int arrays, , latter array of ints.
you don't compile time error, because o1 defined object. @ compile time, hold derived object, in fact every type in java except primitive types long, int, short, byte, char, double, float , boolean. so, @ compile time seems possible object might in fact int[].
Comments
Post a Comment