主题:帮忙解决一条改错题!
haoson
[专家分:10] 发布于 2007-12-28 15:36:00
public class Student{
String id;
String name;
int salary;
public void Test(String id,String name,int salary){ //1
this.id=id;
this.name=name;
this.salary=salary;
}
public void ChangeInfo(String id,int salary){ //2
bollean result;
if(id==this.id){
this.salary=salary; //3
result=TURE;} //4
else{
result=false;}
return result;
}
public boolean changeInfo(String ids,int salarys){ //5
.....
}
}
请帮忙改正以上程序的五处错误。。。
回复列表 (共4个回复)
沙发
zcs179895723 [专家分:330] 发布于 2007-12-28 18:26:00
修改后的:
public class Student{
String id;
String name;
int salary;
public void Test(String id,String name,int salary){ //1 这个没有报错,不过你最好把形式参数名改一下,不然容易混淆
this.id=id;
this.name=name;
this.salary=salary;
}
public boolean ChangeInfo(String id,int salary){ //2 把void改为boolean,void表示不返回值,而你有return语句
boolean result;
if(id==this.id){
this.salary=salary; //3
result=true;} //4 在Java里 true 和false都小写
else{
result=false;}
return result;
}
public boolean changeInfo(String ids,int salarys){ //5 缺少return语句
//.....
}
}
板凳
zhujialin [专家分:50] 发布于 2007-12-28 23:25:00
public class Student{
String id;
String name;
int salary;
public void Test(String id,String name,int salary){ //1这句话使用构造函数
this.id=id;
this.name=name;
this.salary=salary;
}
public void ChangeInfo(String id,int salary){ //2返回值是boolean
bollean result;
if(id==this.id){
this.salary=salary; //3这句话没任何意义
result=TURE;} //4 true
else{
result=false;}
return result;
}
public boolean changeInfo(String ids,int salarys){ //5参数这么写不叫重载,方法重名
.....
}
}
3 楼
dfdongfang402 [专家分:10] 发布于 2008-01-01 18:55:00
public class Student{
String id;
String name;
int salary;
public void Test(String id,String name,int salary){ //1这句话使用构造函数
this.id=id;
this.name=name;
this.salary=salary;
}
public void ChangeInfo(String id,int salary){ //2返回值是boolean
bollean result;
if(id==this.id){
this.salary=salary; //3应该用equals()代替==
result=TURE;} //4 true
else{
result=false;}
return result;
}
public boolean changeInfo(String ids,int salarys){ //不知道
.....
}
}
4 楼
xiaozu0 [专家分:0] 发布于 2008-01-12 09:07:00
public class Student{
String id;
String name;
int salary;
public void Test(String id,String name,int salary){ //1这句话使用构造函数,应把方法名和类名相同,并且不能有void语句。
this.id=id;
this.name=name;
this.salary=salary;
}
public void ChangeInfo(String id,int salary){ //2返回值是boolean,把void改成boolean.
bollean result;
if(id==this.id){
this.salary=salary; //3应该用equals()代替==
result=TURE;} //4 true
else{
result=false;}
return result;
}
public boolean changeInfo(String ids,int salarys){ 要么重载,把参数数量或类型或顺序改一下。要么当是另一个方法,把方法名改为其他。
.....
}
}
我来回复