qq_40196647
丶萌萌哒的小太阳
2017-11-07 01:49

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

  • java

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条回答