你给的代码有些问题:
第5行: public Money(double cost){
这个Money方法没有返回值类型 比如 public void Money(double cost){第6行:this.cost = costs; 可能应该是 this.costs=cost;
因为你的类里没有cost这个实例变量
第5行: public Money(double cost){
这个Money方法没有返回值类型 比如 public void Money(double cost){第6行:this.cost = costs; 可能应该是 this.costs=cost;
因为你的类里没有cost这个实例变量
首先方法没有返回值,再者就是方法体中语句this.cost=costs由问题
应该是this.costs=cost吧
还有this.costs=costs;
他打错了;
profit = Accounting.calculateProfit(this);//Passes itself
this是一个 Money实例,
我猜可能是这样的
public double Accounting.calculateProfit(Money aMoney){//someting}
应该是这样我写错了class Accounting{
public static double calculateProfit(Money aMoney){//someting}
}
class a{
public void i()
{
this.....;
}
}
当你a a1;则a1中的this就是a1。
int cost;
public aMethod(int cost){
this.cost=cost
}
}
this.cost表示本类的成员变量。cost表示本方法的局部变量或参数变量;如果此方法中没有cost,那么cost就表示成员变量。有重名的情况就要用到this关键字。这和super关键字有点像。
代码中“cost”应为“costs”
这是那本经典的JAVA2认证程序员学习指南(红蓝封面英文版)里的代码