java String类或封装类对象 和 普通类对象 有什么不一样?
答案:1 悬赏:50 手机版
解决时间 2021-03-28 05:35
- 提问者网友:嗝是迷路的屁
- 2021-03-27 19:53
为什么 普通类有参构造方法对象 打印出来是一个物理地址;而String类有参构造方法对象打印出来是一个字符串?
最佳答案
- 五星知识达人网友:野味小生
- 2020-02-11 19:19
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.
*
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())
*
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯