丶Gatsby 2017-11-07 02:13 采纳率: 100%
浏览 1316
已采纳

希望各位大佬可以帮我解答一下。

class Person
{
public static void main(String[] args)
{ String name="abc",sex="m",age="19";
System.out.println("The name is "+name+",sex is "+sex+",age is "+age);
Student stu=new Student("2017年",28);
Teacher tea=new Teacher("cjc","abc");
System.out.println(stu);
System.out.println(tea);

}
class Student extends Person
{
private String time;
private int num;
Student(String str,int number)
{
time=str;
num=number;
}
public String toString()
{
return "The time is "+time+"."+"The num is "+num+"."; 
}
}
class Teacher extends Person
{
private String title;
private String section;
Teacher(String str,String num)
{
title=str;
section=num;
}

public String toString() { return "The title " +title+".The section is " +section+".";

}
}

这个程序该怎样修改,才能在输出学生的时候输出的是它的名字,性别,年龄,学号和时间;
在输出教师的时候输出的只有名字,性别,年龄,职称和部门。

  • 写回答

4条回答 默认 最新

  • threenewbee 2017-11-07 02:15
    关注

    student类里面
    public String toString()
    {
    return "名字=" + name + ",性别="+ sex +",年龄="+age+",学号="+num+", 时间=" +time ;
    }
    教师的做法类似

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog