From 31c683359b4f870bbf702dbb8e8afa43eec12cb1 Mon Sep 17 00:00:00 2001 From: Wangyanshu <2680603193@qq.com> Date: Thu, 19 Mar 2026 14:50:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'w2'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w2 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 w2 diff --git a/w2 b/w2 new file mode 100644 index 0000000..f238593 --- /dev/null +++ b/w2 @@ -0,0 +1,31 @@ +// 定义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方法 + } +} \ No newline at end of file