java方法声明无效;需要返回类型
publicclassStudent{privateintstuNo;privateStringstuName;privatecharstuSex;privateints...
public class Student{
private int stuNo;
private String stuName;
private char stuSex;
private int stuAge;
public void Student(int stuNo,String stuName,char stuSex,int stuAge){
this.stuNo = stuNo;
this.stuName = stuName;
this.stuSex = stuSex;
this.stuAge = stuAge;
}
public void setNo(int stuNo){
this.stuNo=stuNo;
}
public void setName(String stuName){
this.stuName=stuName;
}
public void setSex(char stuSex){
this.stuSex=stuSex;
}
public void setAge(int stuAge){
this.stuSex=stuSex;
}
private int getstuNo(){
return stuNo;
}
private String getstuName(){
return stuName;
}
private char getstuSex(){
return stuSex;
}
private int getstuAge(){
return stuAge;
}
public static void main(String []args){
Student people1 = new Student();
Student people2 = new Student("2","张三","男","20");
Student people3 = new Student("3","李四","男","20");
Student people4 = new Student("4","王二","男","20");
people1.setstuNo("1");
people1.setstuName("李刚");
people1.setstuSex("男");
people1.setstuAge("20");
System.out.println("第一名学生:姓名:"+people1.getstuName()+" 学号:"+people1.getstuNo()+" 性别:"+people1.getstuSex()+" 年
龄:"+people1.getstuAge());
System.out.println("第一名学生:姓名:"+people2.getstuName()+" 学号:"+people2.getstuNo()+" 性别:"+people2.getstuSex()+" 年
龄:"+people2.getstuAge());
System.out.println("第一名学生:姓名:"+people3.getstuName()+" 学号:"+people3.getstuNo()+" 性别:"+people3.getstuSex()+" 年
龄:"+people3.getstuAge());
System.out.println("第一名学生:姓名:"+people4.getstuName()+" 学号:"+people4.getstuNo()+" 性别:"+people4.getstuSex()+" 年
龄:"+people4.getstuAge());
}
} 展开
private int stuNo;
private String stuName;
private char stuSex;
private int stuAge;
public void Student(int stuNo,String stuName,char stuSex,int stuAge){
this.stuNo = stuNo;
this.stuName = stuName;
this.stuSex = stuSex;
this.stuAge = stuAge;
}
public void setNo(int stuNo){
this.stuNo=stuNo;
}
public void setName(String stuName){
this.stuName=stuName;
}
public void setSex(char stuSex){
this.stuSex=stuSex;
}
public void setAge(int stuAge){
this.stuSex=stuSex;
}
private int getstuNo(){
return stuNo;
}
private String getstuName(){
return stuName;
}
private char getstuSex(){
return stuSex;
}
private int getstuAge(){
return stuAge;
}
public static void main(String []args){
Student people1 = new Student();
Student people2 = new Student("2","张三","男","20");
Student people3 = new Student("3","李四","男","20");
Student people4 = new Student("4","王二","男","20");
people1.setstuNo("1");
people1.setstuName("李刚");
people1.setstuSex("男");
people1.setstuAge("20");
System.out.println("第一名学生:姓名:"+people1.getstuName()+" 学号:"+people1.getstuNo()+" 性别:"+people1.getstuSex()+" 年
龄:"+people1.getstuAge());
System.out.println("第一名学生:姓名:"+people2.getstuName()+" 学号:"+people2.getstuNo()+" 性别:"+people2.getstuSex()+" 年
龄:"+people2.getstuAge());
System.out.println("第一名学生:姓名:"+people3.getstuName()+" 学号:"+people3.getstuNo()+" 性别:"+people3.getstuSex()+" 年
龄:"+people3.getstuAge());
System.out.println("第一名学生:姓名:"+people4.getstuName()+" 学号:"+people4.getstuNo()+" 性别:"+people4.getstuSex()+" 年
龄:"+people4.getstuAge());
}
} 展开
3个回答
2012-11-28
展开全部
public void Student(int stuNo,String stuName,char stuSex,int stuAge) 这里写多了一个void了,但你这样写也可以,后面new的时候就不要写参数进去就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
作如下更改:
加入函数public Student(){}
Student people2 = new Student("2","张三","男","20");这句数据类型不对更改如下:
Student people2 = new Student(2,"张三",'男',20);
赋初值时,int直接赋值不用加引号
char加单引号
String加双引号
加入函数public Student(){}
Student people2 = new Student("2","张三","男","20");这句数据类型不对更改如下:
Student people2 = new Student(2,"张三",'男',20);
赋初值时,int直接赋值不用加引号
char加单引号
String加双引号
追问
这问题不大
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询