各位帮忙改进下代码
程序代码:
public class Demo_9 { public static void main(String[] args) { Teacher teacher = new Teacher(11111,"张三", "男", 25, "讲师"); teacher.display(); Student student = new Student(9922, "李四", "男", 21, "公寓"); student.display(); } } class Person{ protected String name; protected String sex; protected int age; } class Teacher extends Person{ protected int tnumbers; protected String title; public Teacher(int tnumbers, String name, String sex, int age, String title){ this.name = name; this.sex = sex; this.age = age; this.tnumbers = tnumbers; this.title = title; } public void display(){ javax.swing.JOptionPane.showMessageDialog(null," 职工号 " +tnumbers+ " 名字 " +name + " 性别 " +sex + " 年龄 " +age + " 职称 " +title); } } class Student extends Person{ protected int snumbers; protected String address; public Student(int snumbers, String name, String sex, int age, String address){ this.name = name; this.sex = sex; this.age = age; this.snumbers = snumbers; this.address = address; } public void display(){ javax.swing.JOptionPane.showMessageDialog(null," 学号 " +snumbers + " 名字 " +name + " 性别 " +sex + " 年龄 " +age + " 家庭住址 " +address); } }就是我想把那个display也搞个继承,各位看看是否行得通