package com;
public class Student {
String name;
int studentId;
int age;
String address;
public Student(String name, int studentId, int age, String address) {
this.name = name;
this.studentId = studentId;
this.age = age;
this.address = address;
}
// 学习方法
public void study() {
System.out.println("学生正在学习");
}
// 打电话方法
public void makePhoneCall() {
System.out.println("学生正在打飞机");
}
// 打游戏方法
public void playGame() {
System.out.println("学生正在玩游戏");
}
}
package com;
public class TestStudent {
public static void main(String[] args) {
// 创建一个学生对象
Student student = new Student("张三", 12345, 18, "北京市朝阳区");
// 访问学生属性
System.out.println("姓名:" + student.name);
System.out.println("学号:" + student.studentId);
System.out.println("年龄:" + student.age);
System.out.println("家庭地址:" + student.address);
// 调用学生方法
student.study();
student.makePhoneCall();
student.playGame();
}
}
软件一班作业1
于 2024-05-11 09:40:46 首次发布