读书人

联发科技笔考题

发布时间: 2012-10-31 14:37:32 作者: rapoo

联发科技笔试题

public class Dims {

??? /**
??? ?* @param args
??? ?*/
??? public static void main(String[] args) {
??? ??? // TODO Auto-generated method stub

??? ??? int[][] a = {{1,2},{3,4}};
??? ??? int[] b = (int[])a[1];
??? ??? Object o1 = a;
??? ??? int[][] a2 = (int[][])o1;
??? ??? int[] b2 = (int[])o1;
??? ??? System.out.println(b[1]);
??? }

}

运行时发生异常,在 int[] b2 = (int[])o1;处。类型不匹配

?

public class Pass {

??? /**
??? ?* @param args
??? ?*/
??? public static void main(String[] args) {
??? ??? // TODO Auto-generated method stub

??? ??? int x = 6;
??? ??? Pass p = new Pass();
??? ??? p.doSth(x);
??? ??? System.out.print(" main x = "+x);
??? }

??? void doSth(int x){
??? ??? System.out.print("doSth x = "+x++);
??? }
}
结果:

doSth x = 6 main x = 6

读书人网 >编程

热点推荐