class A {}class Test extends A { public static void main( String[] args) {
A obj=new Test() ;
System.out.println(obj);
}
}
输出为: Test@de6cde
请问这个输出代表什么!是obj的内存地址吗?
因该不是内存地址,因为每次编译输出结果都是这个,不可能每次分配的内存地址都是一个吧! 请解释的详细些! 谢谢!
A obj=new Test() ;
System.out.println(obj);
}
}
输出为: Test@de6cde
请问这个输出代表什么!是obj的内存地址吗?
因该不是内存地址,因为每次编译输出结果都是这个,不可能每次分配的内存地址都是一个吧! 请解释的详细些! 谢谢!
toString
public String toString()
Returns a string representation of the object. In general, the 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 toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', 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())
Returns:
a string representation of the object.
obj.getClass().getName() + '@' + Integer.toHexString(hashCode())
类名(包括了包名)+@+哈希码的十六进制表示
以及这个对象的哈希码(为十六进制形式)的字符串
toString
public String toString()
Returns a string representation of the object.
In general, the 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 toString method for class Object returns a string consisting of the name of the class of which the object is an instance,
the at-sign character `@', 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())
Returns:
a string representation of the object.