java定义一个学生类要求学号,姓名,年龄,三个成员变量
两个构造方法参数分别为:学号、姓名和;学号、姓名、年龄。要使用THIS关键字,将接收到的实参的值为每一个对应的成员变量赋值。请大家帮帮忙在线等...
两个构造方法参数分别为:学号、姓名和;学号、姓名、年龄。要使用THIS关键字,将接收到的实参的值为每一个对应的成员变量赋值。请大家帮帮忙在线等
展开
3个回答
展开全部
class Student{
private int STU_NUM;
private String STU_NAME;
private int STU_AGE;
public Student(int NUM,String NAME){
this.STU_NAME=NAME;
this.STU_NUM=NUM;
}
public Student(int NUM,String NAME,int AGE){
this.STU_NAME=NAME;
this.STU_NUM=NUM;
this.STU_AGE=AGE;
}
}
展开全部
public class Student{
public int Sno; //学号
public String Sname; //Student Name;
public int Sage; //年龄
public Student(){
} //无参构造器
public Student(int Sno,String Sname, int Sage){
this.Sno=Sno;
this.Sname=Sname;
this.Sage=Sage;
}
}
如果要封装, 将属性改为 private 的话 继续追问
public int Sno; //学号
public String Sname; //Student Name;
public int Sage; //年龄
public Student(){
} //无参构造器
public Student(int Sno,String Sname, int Sage){
this.Sno=Sno;
this.Sname=Sname;
this.Sage=Sage;
}
}
如果要封装, 将属性改为 private 的话 继续追问
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Student {
private String number;
private int age;
private String name;
Student(String number,String name){
this.number = number;
this.name = name;
}
Student(String number,String name,int age){
this.number = number;
this.name = name;
this.age = age;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
private String number;
private int age;
private String name;
Student(String number,String name){
this.number = number;
this.name = name;
}
Student(String number,String name,int age){
this.number = number;
this.name = name;
this.age = age;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询