请问这个程序错在哪里?? FatherRevenue f=new FatherRevenue (15.0,1995);SonRevenue s=new SonRevenue(15.0,1995); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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,这就隐藏了超类被继承的变量 程序错在派生类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); 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;} org.w3c.dom 终于找到国内的免费JSP/Servlet空间了,想找地方练手的新手快来吧! 百分求:用JAVA写字符串化简的方法 怎样判断字符串的内容? 监听器到底是什么意思? 二维数组初始化问题 thanking in java 的prg237中的例题!进来帮帮我! 急::请指点!!(Thank You!!) 请问:不创建临时文件如何将内容为图片的InputStream显示到HTML页面中? 怎样使用jdbc驱动? 好奇的人请进来,( 分多了,快毕业了,路人也进来领分) 怎样用java实现浏览器?
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,这就隐藏了超类被继承的变量
在其构造方法里面没有显示地构造父类,因此出错。//因为父类没有提供无参数的构造方法
在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);
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;
}