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.

35 lines
983 B

public class StudentProgram {
public static void main(String[] args) {
// 实例化两个Student对象
Student student1 = new Student("S001", "张三", 85.5);
Student student2 = new Student("S002", "李四", 92.0);
// 调用study方法
student1.study();
student2.study();
}
}
// 定义Student类
class Student {
// 属性
private String studentId; // 学号
private String name; // 姓名
private double score; // 成绩
// 构造方法
public Student(String studentId, String name, double score) {
this.studentId = studentId;
this.name = name;
this.score = score;
}
// study()方法
public void study() {
System.out.println(name + " 正在学习Java编程...");
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
}