丶Gatsby 2017-11-07 01:49 采纳率: 100%
浏览 884
已采纳

希望各位大牛可以赐教。。。。

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+".";

}
}

这个程序该怎样修改,才能在输入学生和老师时调用其该有的参数,而不是整体全部输出student 和 teacher

  • 写回答

6条回答 默认 最新

  • threenewbee 2017-11-07 01:53
    关注

    就像你写的public String toString()
    你想输出什么,就在里面写什么。

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

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式