A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

public class 关于toString和print方法 {
        public static void main(String[] args) {
                /**
                 * System.out.println(obj);
                 * System.out.println(obj.toString());
                 * obj是一个对象名,或者数组名
                 *
                 * 此时,默认执行过程是: println()方法, 调用 obj.toString() 方法.
                 * 因为,obj.toString()方法的返回值,一般都是String类型
                 *
                 * 当obj是一个对象名, 往往重写 toString()方法
                 *
                 * 当obj是一个数组名, 可能会重写println()方法,也可能重写toString()方法
                 *
                 *                         言外之意:
                *                 当!!!
                 *         println()方法, toString()方法,都没有重写!!
                 * System.out.println(obj);
                 * System.out.println(obj.toString());    完全一样!!*/   /* 例如 int[] */  /**
                 *
                *                 当!!!
                 *         只重写了toString()方法!!
                 * System.out.println(obj)
                 * System.out.println(obj.toString())     完全一样!!*/   /* 例如  String */  /**
                 *
                *                 当!!!
                 *         只重写println()方法!!
                 * System.out.println(obj);
                 * System.out.println(obj.toString());         绝对不可能一样!! */   /* 例如  char[] */  /**
                 *
                *                 当!!!
                 *         println()方法, toString()方法,都有重写!!
                 * System.out.println(obj);
                 * System.out.println(obj.toString());         绝对不可能一样!!
                 */
        }
}

评分

参与人数 3黑马币 +17 收起 理由
silencelj + 5 赞一个!
崔小可 + 6 很给力!
xuelanghu120 + 6

查看全部评分

6 个回复

倒序浏览
额,新人各种求- -目前正在努力中
回复 使用道具 举报
恩,相当不错
回复 使用道具 举报
笑爷 来自手机 中级黑马 2015-5-21 22:12:35
板凳
写的很好
回复 使用道具 举报
写的很好,谢谢!
回复 使用道具 举报

很感谢!谢谢!!
回复 使用道具 举报

谢谢支持!!:)
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马