3 changed files with 36 additions and 0 deletions
Binary file not shown.
Binary file not shown.
@ -0,0 +1,36 @@ |
|||
// 1. 定义 Student 类
|
|||
class Student { |
|||
// 定义题目要求的三个属性
|
|||
int studentId; // 学号
|
|||
String name; // 姓名
|
|||
double score; // 成绩
|
|||
|
|||
// 定义 study 方法
|
|||
public void study() { |
|||
// 这里打印学生的学习信息,用到上面的属性
|
|||
System.out.println("学生 " + name + " (学号:" + studentId + ") 正在认真学习,当前成绩是:" + score); |
|||
} |
|||
} |
|||
|
|||
// 2. 主类(包含 main 方法)
|
|||
public class StudentTest { |
|||
public static void main(String[] args) { |
|||
// 实例化第一个学生对象
|
|||
Student stu1 = new Student(); |
|||
// 给第一个学生的属性赋值
|
|||
stu1.studentId = 20240101; |
|||
stu1.name = "张三"; |
|||
stu1.score = 92.5; |
|||
|
|||
// 实例化第二个学生对象
|
|||
Student stu2 = new Student(); |
|||
// 给第二个学生的属性赋值
|
|||
stu2.studentId = 20240102; |
|||
stu2.name = "李四"; |
|||
stu2.score = 88.0; |
|||
|
|||
// 调用方法
|
|||
stu1.study(); |
|||
stu2.study(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue