|
2鱼币
拜托
问题:编写一个学生和教师数据输入和显示程序,学生和教师数据输入和显示,学生数据有编号、姓名、班级和成绩,
教师数据有编号、姓名、职称和部门。要求编号、姓名输入和显示设计成一个Person类,并作为学生数据操作类Student和教师数据操作类Teacher的父类。
具体疑惑:控制台为什么会输出这个,要怎么解决?
控制台输出: Text04.Student@677327b6
Text04.Teacher@14ae5a5
代码如下:
package Text04;
public class Program04 {
public static void main(String[] args) {
Student student = new Student(0124,"张三","物联一班",93);
System.out.println(student);
Teacher teacher = new Teacher(0021,"李四","特级教师","信息工程部");
System.out.println(teacher);
}
}
//创建一个person类
package Text04;
public class Person {
private int number;
private String name;
public Person(int number, String name) {
this.number = number;
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
//创建一个Student类
package Text04;
public class Student extends Person{
private String clbum;
private int grade;
public Student(int number, String name, String clbum, int grade) {
super(number, name);
this.clbum = clbum;
this.grade = grade;
}
public String getClbum() {
return clbum;
}
public void setClbum(String clbum) {
this.clbum = clbum;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
}
//创建一个Teacher类
package Text04;
public class Teacher extends Person {
private String rank;
private String section;
public Teacher(int number, String name, String rank, String section) {
super(number, name);
this.rank = rank;
this.section = section;
}
}
本帖最后由 wuliangtdi 于 2020-11-2 15:54 编辑
重写toString方法就行了,没有重写toString方法就是打印地址值
|
最佳答案
查看完整内容
重写toString方法就行了,没有重写toString方法就是打印地址值
|