Java开发文档的使用与Hashcode的入门(老鸟勿进)

来源:互联网 发布:java iterator 将int 编辑:程序博客网 时间:2024/06/09 18:14

我自学C++的进程中,没搞定阅读文档的问题。

这次借着机会重撸Java,这个坑一定要填上。于是用最入门的Object()类来入门。


Java单一继承,那么意味着,object所有的方法,对象(们)都能用。

class Dog{    String print(){        return "This is a horrible dog";    }    //在此重写了toString方法。本身在toString文档,官方要求也要重写此方法。    //public String toString(){        //return "Rewrite default toString method.";    //}  }public class TestToString {    public static void main(String[] args) {        Dog d = new Dog();        System.out.println("d:= " + d.print());        System.out.println("d:= " + d);        System.out.println("d:= " + d.toString());        System.out.println("get and show out hashcode via return int by hashcode() funciton");        System.out.println("d:= " + d.hashCode());    }}



运行结果:

d:= This is a horrible dog
d:= Dog@2a139a55
d:= Dog@2a139a55
get and show out hashcode via return int by hashcode() funciton
d:= 705927765

toString官档返回值为16进制,hashcode()方法返回值为int。开计算器演算:


0 0