你给的代码有些问题:
第5行: public Money(double cost){
这个Money方法没有返回值类型 比如 public void Money(double cost){第6行:this.cost = costs; 可能应该是 this.costs=cost;
因为你的类里没有cost这个实例变量

解决方案 »

  1.   

    我也觉得你给的代码有点问题吧,
    首先方法没有返回值,再者就是方法体中语句this.cost=costs由问题
    应该是this.costs=cost吧
      

  2.   

    他的意思是Money是构造子;
    还有this.costs=costs;
    他打错了;
    profit = Accounting.calculateProfit(this);//Passes itself
    this是一个 Money实例,
    我猜可能是这样的
    public double Accounting.calculateProfit(Money aMoney){//someting}
      

  3.   

    "passes itself"就是没生成一个Money的实例就会自动把该实例通过calculateProfit()把自给传递过去,然后在这个方法里面处理Money的相关数据之后返回一个double.
    应该是这样我写错了class Accounting{
       public static double calculateProfit(Money aMoney){//someting}
    }
      

  4.   

    其实很简单吧,
           class a{
            public void i()
    {
        this.....;
    }
    }
    当你a a1;则a1中的this就是a1。
      

  5.   

    class AClass{
        int cost;
        public aMethod(int cost){
            this.cost=cost
        }
    }
    this.cost表示本类的成员变量。cost表示本方法的局部变量或参数变量;如果此方法中没有cost,那么cost就表示成员变量。有重名的情况就要用到this关键字。这和super关键字有点像。
      

  6.   

    对不住大家
    代码中“cost”应为“costs”
    这是那本经典的JAVA2认证程序员学习指南(红蓝封面英文版)里的代码