需求说明:
编写学员类,输出学员类相关信息
编写教员类,输出教员类相关信息
代码:
学员类:
public class Student {
String name;
int age;
int num;
String hobby;
public void showInfo() {
System.out.println(name+"
年龄:"+age+"
就读于:"+num+"班
爱好:"+hobby);
}
}
教员类:
public class Teacher {
String name;//名字
String specialty;//专业
String teach;//教授课程
int age;
public void showInfo() {
System.out.println(name+"
专业方向:"+specialty+"
教授课程:"+teach+"
工龄"+age);
}
}
测试类:
public class Text {
public static void main(String[] args) {
Student stu = new Student();
stu.name = "张浩";
stu.age = 10;
stu.num = 15;
stu.hobby = "篮球";
stu.showInfo();
Teacher tea = new Teacher();
tea.name = "王老师";
tea.specialty = "计算机";
tea.teach = "使用JAVA语言理解程序逻辑";
tea.age = 5;
tea.showInfo();
}
}
运行结果: