网站系统修改,南漳网站开发,宿舍网站建设目的,淘宝网站首页是用什么软件做的toString()方法在Object类中定义#xff0c;其返回值是String类型#xff0c;返回类名和它的引用地址。在进行String与其它类型数据的连接操作时#xff0c;自动调用toString()方法。
Account account new Account();
System.out.println(account); //com.atyeman.Account…toString()方法在Object类中定义其返回值是String类型返回类名和它的引用地址。在进行String与其它类型数据的连接操作时自动调用toString()方法。
Account account new Account();
System.out.println(account); //com.atyeman.Account1b6d3586
System.out.println(account.toString()); //com.atyeman.Account1b6d3586Date nownew Date();
System.out.println(“now”now); //相当于下面
System.out.println(“now”now.toString()); //因为Date重写过所以输出的是自定义的时间信息。可以根据需要在用户自定义类型中重写toString()方法如String 类重写了toString()方法返回字符串的值。
s1“hello”;
System.out.println(s1);//相当于System.out.println(s1.toString());输出“hello”