You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
839 B

// 定义Student类
class Student {
// 定义属性
int studentId;
String name;
double score;
// 定义study方法
void study() {
System.out.println("学生" + name + "(学号:" + studentId + ")正在学习,当前成绩为:" + score);
}
}
// 主类
public class StudentTest {
public static void main(String[] args) {
// 实例化第一个Student对象
Student student1 = new Student();
student1.studentId = 101;
student1.name = "张三";
student1.score = 92.5;
student1.study(); // 调用study方法
// 实例化第二个Student对象
Student student2 = new Student();
student2.studentId = 102;
student2.name = "李四";
student2.score = 88.0;
student2.study(); // 调用study方法
}
}