java中tostring的重载

class student {
    private String name="zhang";
    private int num=12;

    @Override
    public String toString() {
        return "名字为:" + name +","+ "学号为:" + num;
    }
}

public class Main {
    public static void main(String[] args) {
        student stu = new student();

        System.out.println(stu);
    }
}

 

posted @ 2019-10-08 22:42  pycodego  阅读(437)  评论(0编辑  收藏  举报