Object--toString - 日理万妓 2022-05-12 08:12 203阅读 0赞 package jave; /*Object--toString*/ public class ToSring { public static void main(String[] args) { Dog d = new Dog(); System.out.println("d = " + d); } } class Dog { //重写toString类,切记:方法名toString要与基类Object一致,否则编译不会出错,但运行会一直得不出正确的结果 public String toString() { return "I'm a cool dog !"; } }
还没有评论,来说两句吧...