1定义学生类:在Java中创建一个名为"Student'的类,包括属性:姓名、年龄、性别.身高、体重。并提供相关的set和get方法进行读写操作。
时间: 2024-02-27 20:59:20 浏览: 33
好的,下面是一个简单的学生类的定义,包括姓名、年龄、性别、身高和体重等属性,并提供了 getter 和 setter 方法用于访问和修改这些属性。
```java
public class Student {
private String name; // 姓名
private int age; // 年龄
private String gender; // 性别
private double height; // 身高
private double weight; // 体重
// 构造方法
public Student(String name, int age, String gender, double height, double weight) {
this.name = name;
this.age = age;
this.gender = gender;
this.height = height;
this.weight = weight;
}
// get方法
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getGender() {
return gender;
}
public double getHeight() {
return height;
}
public double getWeight() {
return weight;
}
// set方法
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setGender(String gender) {
this.gender = gender;
}
public void setHeight(double height) {
this.height = height;
}
public void setWeight(double weight) {
this.weight = weight;
}
}
```
以上是一个简单的学生类的定义,包括姓名、年龄、性别、身高和体重等属性,并提供了 getter 和 setter 方法用于访问和修改这些属性。
相关推荐
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)