fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. class Program
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Student stu=new Student("abc", "m", "19", "2017年", 28);
  13. Teacher tea=new Teacher("cjc","abc");
  14. System.out.println(stu);
  15. System.out.println(tea);
  16. }
  17. }
  18.  
  19. class Person
  20. {
  21. public String name;
  22. public String sex;
  23. public String age;
  24. public String toString()
  25. {
  26. return "name=" + name + ",sex=" + sex + ",age=" + age;
  27. }
  28. public Person(String name, String sex, String age)
  29. {
  30. this.name = name; this.sex = sex; this.age = age;
  31. }
  32. }
  33. class Student extends Person
  34. {
  35. public String time;
  36. public int num;
  37. public Student(String name, String sex, String age, String time, int num)
  38. {
  39. super(name, sex, age);
  40. this.time = time; this.num = num;
  41. }
  42. public String toString()
  43. {
  44. return "名字=" + name + ",性别=" + sex + ",年龄=" + age + ",学号=" + num + ", 时间=" + time;
  45. }
  46. }
  47. class Teacher extends Person
  48. {
  49. public String title;
  50. public String section;
  51. public Teacher(String str,String num)
  52. {
  53. super("","","");
  54. title = str;
  55. section = num;
  56. }
  57. public String toString() { return "The title " +title+".The section is " +section+"."; }
  58. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
名字=abc,性别=m,年龄=19,学号=28, 时间=2017年
The title cjc.The section is abc.