0708--oop作业--创建学员类和教员类
作者:互联网
需求说明:
编写学员类,输出学员类相关信息
编写教员类,输出教员类相关信息
代码:
学员类:
public class Student { String name; int age; int num; String hobby; public void showInfo() { System.out.println(name+"\n年龄:"+age+"\n就读于:"+num+"班\n爱好:"+hobby); } }
教员类:
public class Teacher { String name;//名字 String specialty;//专业 String teach;//教授课程 int age; public void showInfo() { System.out.println(name+"\n专业方向:"+specialty+"\n教授课程:"+teach+"\n工龄"+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(); } }
运行结果:
标签:String,学员,tea,age,stu,0708,oop,public,name 来源: https://www.cnblogs.com/Dean-0/p/11152217.html