FatherRevenue f=new FatherRevenue (15.0,1995);
SonRevenue s=new SonRevenue(15.0,1995);

解决方案 »

  1.   

    public class FatherRevenue{
    protected double money;
    protected int year; protected FatherRevenue(double m,int y)
    {
    money=m;
    year=y;
    }
    public double Getmoney(){
    return money=money*0.02;
    }
    public int Getyear(){
    return year;
    } public static void main(String args[ ])
    {
    FatherRevenue f = new FatherRevenue (11.0,1993);
    SonRevenue s=new SonRevenue(15.0,1995);
    //s.Getyear();
    if(s.Getyear()>1995)
    System.out.println(f.Getmoney());
    else
    System.out.println(s.Getmoney());
    }
    }
    class SonRevenue extends FatherRevenue{                                                                   int  year;
    SonRevenue(double a,int b){
    super(a,b);
    } public double Getmoney(){
    money=money*0.03;
    return money;
    }
    public int Getyear()
    {
    return year;
    }
    }
    注:超类变量应该protected,另外子类继承超类,变量自动继承.你刚刚的代码中,在子类中重新定义了money和year,这就隐藏了超类被继承的变量
      

  2.   

    程序错在派生类SonRevenue的构造方法。
    在其构造方法里面没有显示地构造父类,因此出错。//因为父类没有提供无参数的构造方法
    在SonRevenue构造方法第一行加上 super((float)m, y);这个。。
    另外
    FatherRevenue f(11.0,1993)=new FatherRevenue ();
    SonRevenue s(15.0,1995)=new SonRevenue();
    这两行什么啊。。
    改成:
    FatherRevenue f =new FatherRevenue(11.0F, 1993);
    SonRevenue s=new SonRevenue(15.0, 1995);
      

  3.   


    FatherRevenue f=new FatherRevenue (15.0,1995);
    SonRevenue s=new SonRevenue(15.0,1995);SonRevenue(double m,int y){
        super(m,y);                        //这个不能少的
    money=m;
    year=y;
    }