永发信息网

javaString类或封装类对象和普通类对象有什么不一样?

答案:1  悬赏:60  手机版
解决时间 2021-12-19 10:11
  • 提问者网友:杀手的诗
  • 2021-12-19 01:07
为什么 普通类有参构造方法对象 打印出来是一个物理地址;而String类有参构造方法对象打印出来是一个字符串?
最佳答案
  • 五星知识达人网友:第四晚心情
  • 2021-12-19 01:43
Sting类复写了toString()方法。
String类复写后的toString()方法源代码:
 
    public String toString() {
        return this;
    }Object类的toString()方法源代码:

/**
     * Returns a string representation of the object. In general, the
     * {@code toString} method returns a string that
     * "textually represents" this object. The result should
     * be a concise but informative representation that is easy for a
     * person to read.
     * It is recommended that all subclasses override this method.
     * 


     * The {@code toString} method for class {@code Object}
     * returns a string consisting of the name of the class of which the
     * object is an instance, the at-sign character `{@code @}', and
     * the unsigned hexadecimal representation of the hash code of the
     * object. In other words, this method returns a string equal to the
     * value of:
     * 


     * 

     * getClass().getName() + '@' + Integer.toHexString(hashCode())
     * 
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯