主题:关于方法重载的问题,希望帮助
class STUDENT{ /*学生的类*/
int s_number; /*学号*/
StringBuffer s_name=new StringBuffer(); /*学生名字*/
int nuber_of_the_course_you_have_selected=0; /*选课数目*/
StringBuffer c_name[]; /*定义数组存放选课名称*/
int c_num[]; /*定义数组存放选课的编号*/
void STUDENT(){
c_name = new StringBuffer[4];
c_name[0] = new StringBuffer();
c_name[1] = new StringBuffer();
c_name[2] = new StringBuffer();
c_name[3] = new StringBuffer();
c_num=new int[4];
}
void STUDENT(StringBuffer s_name,int s_number){
c_name = new StringBuffer[4];
c_name[0] = new StringBuffer();
c_name[1] = new StringBuffer();
c_name[2] = new StringBuffer();
c_name[3] = new StringBuffer();
c_num=new int[4];
this.s_name=s_name;
this.s_number=s_number;
}/*初始化方法。有带参数不带参数2种*/
boolean SELECT_COURSE(StringBuffer c_name,int c_num){
if (nuber_of_the_course_you_have_selected>=4){
System.out.println("满了,你已经选择了4门课程,不需要继续选择!");
return false;
}
this.c_name[nuber_of_the_course_you_have_selected]=c_name;
this.c_num[nuber_of_the_course_you_have_selected]=c_num;
nuber_of_the_course_you_have_selected++;
return true;
}/*这个方法选课程*/
void SET_NAME(StringBuffer s_name){
this.s_name=s_name;
}/*这个方法设置学生名字*/
void SET_NUMBER(int s_number){
this.s_number=s_number;
}/*这个方法设置学生学号*/
}
/*上述定义的student类*/
/*下边对其操作,生成5个实例*/
public class a{
public static void main (String args[]){
int i=0;
boolean b1,b2;
StringBuffer t=new StringBuffer("ma");
StringBuffer c=new StringBuffer("java");
STUDENT student[];
student=new STUDENT[5];
for (i=0;i<=4;i++){
[color=800080]student[i]=new STUDENT(t,i);[/color]
}
}
}
为什么不行会产生编译错误,但是如果把student[i]=new STUDENT(t,i);改student[i]=new STUDENT();就不产生编译错误
int s_number; /*学号*/
StringBuffer s_name=new StringBuffer(); /*学生名字*/
int nuber_of_the_course_you_have_selected=0; /*选课数目*/
StringBuffer c_name[]; /*定义数组存放选课名称*/
int c_num[]; /*定义数组存放选课的编号*/
void STUDENT(){
c_name = new StringBuffer[4];
c_name[0] = new StringBuffer();
c_name[1] = new StringBuffer();
c_name[2] = new StringBuffer();
c_name[3] = new StringBuffer();
c_num=new int[4];
}
void STUDENT(StringBuffer s_name,int s_number){
c_name = new StringBuffer[4];
c_name[0] = new StringBuffer();
c_name[1] = new StringBuffer();
c_name[2] = new StringBuffer();
c_name[3] = new StringBuffer();
c_num=new int[4];
this.s_name=s_name;
this.s_number=s_number;
}/*初始化方法。有带参数不带参数2种*/
boolean SELECT_COURSE(StringBuffer c_name,int c_num){
if (nuber_of_the_course_you_have_selected>=4){
System.out.println("满了,你已经选择了4门课程,不需要继续选择!");
return false;
}
this.c_name[nuber_of_the_course_you_have_selected]=c_name;
this.c_num[nuber_of_the_course_you_have_selected]=c_num;
nuber_of_the_course_you_have_selected++;
return true;
}/*这个方法选课程*/
void SET_NAME(StringBuffer s_name){
this.s_name=s_name;
}/*这个方法设置学生名字*/
void SET_NUMBER(int s_number){
this.s_number=s_number;
}/*这个方法设置学生学号*/
}
/*上述定义的student类*/
/*下边对其操作,生成5个实例*/
public class a{
public static void main (String args[]){
int i=0;
boolean b1,b2;
StringBuffer t=new StringBuffer("ma");
StringBuffer c=new StringBuffer("java");
STUDENT student[];
student=new STUDENT[5];
for (i=0;i<=4;i++){
[color=800080]student[i]=new STUDENT(t,i);[/color]
}
}
}
为什么不行会产生编译错误,但是如果把student[i]=new STUDENT(t,i);改student[i]=new STUDENT();就不产生编译错误