当前位置: 代码迷 >> Java相关 >> 问题哟!!~找错
  详细解决方案

问题哟!!~找错

热度:232   发布时间:2007-06-02 23:42:00.0
问题哟!!~找错

public class Student {

private String stuId;

private String stuName;

private String stuSex;

public void Studenter(String stuId , String stuName ,String stuSex){

this.stuId = stuId ;
this.stuName = stuName ;
this.stuSex = stuSex ;
}

public String getStuId() {
return stuId;
}

public void setStuId(String stuId) {
this.stuId = stuId;
}

public String getStuName() {
return stuName;
}

public void setStuName(String stuName) {
this.stuName = stuName;
}

public String getStuSex() {
return stuSex;
}

public void setStuSex(String stuSex) {
this.stuSex = stuSex;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根


Student[] student = new Student[3] ;



student[0] = new Student() ;

student[0].Studenter("1000" , "luyihua" , "男");


student[1] = new Student() ;

Studenter("1000" , "luyihua" , "男");

for(int i = 0 ; i < 3 ; i ++ ){

System.out.println(student[i].Studenter());
}

}
}
错在哪里呀???


----------------解决方案--------------------------------------------------------

呵呵,你的错误不少哦~~~

public class Student {

private String stuId;

private String stuName;

private String stuSex;

public void Studenter(String stuId , String stuName ,String stuSex){ //你的构造函数未与主函数同名,改为Student

this.stuId = stuId ;
this.stuName = stuName ;
this.stuSex = stuSex ;
}

public String getStuId() {
return stuId;
}

public void setStuId(String stuId) {
this.stuId = stuId;
}

public String getStuName() {
return stuName;
}

public void setStuName(String stuName) {
this.stuName = stuName;
}

public String getStuSex() {
return stuSex;
}

public void setStuSex(String stuSex) {
this.stuSex = stuSex;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根


Student[] student = new Student[3] ;



student[0] = new Student() ; //示例化一对象student[0]应正确调用构造函数

student[0].Studenter("1000" , "luyihua" , "男");//可为student[0]=new Student("1000" , "luyihua" , "男");
//另两个对象类似构造..

student[1] = new Student() ;

Studenter("1000" , "luyihua" , "男");

for(int i = 0 ; i < 3 ; i ++ ){

System.out.println(student[i].Studenter()); //你的意思是打印出3个对象的信息是吧

} //应该调用类中的成员变量stuId,stuName,stuSex

} //可改为 System.out.println(student[i].stuId+","+student[i].stuName+","+student[i].stuSex);
}

这样编译一下应该可以了的...


----------------解决方案--------------------------------------------------------
[QUOTE]public void Studenter(String stuId , String stuName ,String stuSex){ //你的构造函数未与主函数同名,改为Student

this.stuId = stuId ;
this.stuName = stuName ;
this.stuSex = stuSex ;
}
[/QUOTE]构造函数没有返回值。
----------------解决方案--------------------------------------------------------

public class Student {

private String stuId;

private String stuName;

private String stuSex;

public Student(String stuId , String stuName

,String stuSex)
{
this.stuId = stuId ;
this.stuName = stuName ;
this.stuSex = stuSex ;
}

public static void main(String args[])
{
Student[] student=new Student[3];
student[0]=new Student("1000" , "luyihua" , "男

");
student[1]=new Student("1000" , "luyihua" , "男

");
student[2]=new Student("1000" , "luyihua" , "男

");
for(int i=0;i<student.length;i++)
System.out.println(student

[i].stuId+":"+student[i].stuName+":"+student

[i].stuSex);
}
}
这样不就可以了吗,为何写那么多啊?


----------------解决方案--------------------------------------------------------
  相关解决方案