package oop;
public class Student {
//建造一个模板
//属性
String name; //姓名
int age; //年龄
String classRoom; //班级
String hobby; //爱好、
//方法
public void show() {
System.out.println(name + "
年龄" + age + "
就读于:"
+ classRoom + "
爱好:" + hobby);
}
}
package oop;
public class InitialStudent {
public static void main(String[]args){
//建立一个对象
Student student = new Student();
//为对象赋值
student.name = "张浩";
student.age = 10;
student.classRoom = "51班";
student.hobby = "篮球;
//调用方法
student.show();
}
}
package oop;
public class Teacher {
//创建一个模板 1属性 2 方法
//属性
String name; //姓名
String major; //专业方向
String course; //教授课程
int schoolAge; //教龄
//方法
public void show() {
System.out.println(name+"
专业方向"
+major+"
教授课程:"+course+"
教龄"+schoolAge);
}
}
package oop;
public class InitialTeacher {
public static void main(String[] args) {
//创建一个对象
Teacher teacher = new Teacher();
//为刚出生的对象赋值
teacher.name = "王老师";
teacher.major = "计算机";
teacher.course = "使用Java语言理解程序逻辑";
teacher.schoolAge = 5;
//调用方法
teacher.show();
}
}