重写
package Demo08;
public class Person {
private String name;
private int age;
public Person(int age,String name) {
this.age = age;
this.name=name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
package Demo08;
import java.util.SplittableRandom;
public class Demo08main {
public static void main(String[] args) {
Person person=new Person(18,"lcz");
String s=person.toString();
System.out.println(s);
System.out.println(person);
}
}
-
重写前
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hIvNkUCe-1619105537004)(C:\Users\江俊龙\AppData\Roaming\Typora\typora-user-images\image-20210413211309698.png)]
-
重写后
-
重写前
[外链图片转存中…(img-hIvNkUCe-1619105537004)]
-
重写后
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-najnaQcl-1619105537010)(C:\Users\江俊龙\AppData\Roaming\Typora\typora-user-images\image-20210413211436713.png)]