在一个学校的人事管理系统中,要储存教师和学生的信息,先采用了向对象思想分析得到教师类和学生类。其属性如下所示:1、父类
package jicheng1;
public class Person {
public String name;
public int age;
public void eating() {
System.out.println("干饭了!");
}
}
2、子类1
package jicheng1;
public class Teacher extends Person{
public float salary;
public void prelection() {
System.out.println("上课了!");
}
}
子类2
package jicheng1;
public class Student extends Person{
public float grade;
public void examination() {
System.out.println("及格了!yeah!");
}
}
3、测试
package jicheng1;
public class Test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Student student=new Student();
student.name="张三";
student.age=18;
System.out.println(student.name);
System.out.println(student.age);
student.eating();
student.examination();
Teacher teacher=new Teacher();
teacher.name="李四";
teacher.age=45;
System.out.println(teacher.name);
System.out.println(teacher.age);
teacher.eating();
teacher.prelection();
}
}
4、结果