java 写语句 创建一个学生类,类内具体信息设置如下 类名:student 变量:(访问权限均为p

2024-11-28 00:48:08
推荐回答(2个)
回答1:

public class Student {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

public boolean inSameAge(Student s){
if(s.age==age){
return true;
}else{
return false;
}
}
}

回答2:

public class student {
private String name;

private int age;
public student(){
name="无名氏";
age=20;
}
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
public boolean inSameAge(student s){
if (s.getAge() == this.age)
return true;
else
return false;
}

}