本帖最后由 寇龙飞 于 2012-8-26 17:00 编辑
- package com.itheima.zhangxiaoxiang;
- public class DifferentsOfObject {
-
- public static void main(String[] args) {
-
- String[] arrString = new String[]{};
- int[] arrInt = new int[]{};
-
- /*这句okay*/
- Object[] arrObjectString = arrString;
-
- /*这里报错,Type mismatch: cannot convert from int[] to Object[]*/
- Object[] arrObjectInt = arrInt;
- /*我根据张孝祥老师在“数组与Object的关系中讲的,理解的错误原因为int不是Object的子类,所以不行(int根本就不是类)”*/
-
- /*但是,这个为什么可以*/
- int i = 0;
- print(i);
- /*这个怎么解释,多态??int不是类,跟不是Object的子类*/
- /*强制类型转化???int到Object?怎么说?*/
- }
-
- //这个函数毕老师最常用了吧
- public static void print(Object obj) {
- System.out.println(obj);
- }
- }
复制代码 |