java声明两个类,一个学生类,一个教师类,并输出相关信息

2020-10-29 教育 301阅读
//没用到访问器(set、get)
public class TestClass {
public static void main(String[] args) {
//创建一个学生对象
Student xiaoming=new Student(2011001,"小明","打篮球、足球、玩游戏","175cm");
//创建一个老师对象
Teacher wanglaoshi=new Teacher("Java","王老师","编程、业余黑客","185cm");
}
}
//学生类
class Student {
//学生的学号,姓名,爱好,身高
int St_Id;
String St_Name,St_Love,St_Stature;
public Student(int id, String name, String love, String stature) {
this.St_Id=id;
this.St_Name=name;
this.St_Love=love;
this.St_Stature=stature;
//自我介绍下:
System.out.println("我是一名学生,我的名字是:"+St_Name
+" 我的学号是:"+St_Id
+" 我身高"+St_Stature
+" 我的爱好有: "+St_Love);
}
}
//教师类
class Teacher{
//教师的学号,姓名,爱好,身高
String T_Name,T_course,T_Love,T_Stature;
public Teacher(String course, String name, String love, String stature) {
this.T_course=course;
this.T_Name=name;
this.T_Love=love;
this.T_Stature=stature;
//自我介绍下:
System.out.println("我是一名学生,我的名字是:"+T_Name
+" 我带你们的课程是:"+T_course
+" 我身高"+T_Stature
+" 我的爱好有: "+T_Love);
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com