package _01ToObject.Object;
public class Test {
String color;
int a;
boolean isCool;
//方法的覆盖,toString,覆盖了Object父类里面的toString();
@Override
public String toString() {
return "Test [color=" + color + ", a=" + a + ", isCool=" + isCool + "]";
}
public String toString(int a) {
return "Test [color=" + color + ", a=" + a + ", isCool=" + isCool + "]";
}
public static void main(String[] args) {
Test t1 = new Test();
t1.color = "White";
t1.a = 123;
t1.isCool = true;
System.out.println(t1);
System.out.println(t1.toString());
//我就是要重载一个方法,啦啦啦
System.out.println(t1.toString(1));
}
}
关于Java中的父类Objact的toString()
最新推荐文章于 2022-08-08 19:19:52 发布