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

2024年11月28日 00:48
有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;
}

}