为什么compute_2无法继承compute:
class compute
{
int i1;
int i2;
compute(int m,int n)
{
i1=m;
i2=n;
}
int sum()
{
return i1+i2;
}
int minus()
{
return i1-i2;
}
}
class compute_2 extends compute
{
int multiply()
{
return i1*i2;
}
double divide()
{
return i1/i2;
}
}
编译compute_2.java时报错提示是:compute_2.java:1:compute(int,int) in compute cannot be applied to () class compute_2 extends compute于是我把compute的构造函数注释掉以后又可以编译了,不知道为什么会这样啊?
麻烦各位了!!
class compute
{
int i1;
int i2;
compute(int m,int n)
{
i1=m;
i2=n;
}
int sum()
{
return i1+i2;
}
int minus()
{
return i1-i2;
}
}
class compute_2 extends compute
{
int multiply()
{
return i1*i2;
}
double divide()
{
return i1/i2;
}
}
编译compute_2.java时报错提示是:compute_2.java:1:compute(int,int) in compute cannot be applied to () class compute_2 extends compute于是我把compute的构造函数注释掉以后又可以编译了,不知道为什么会这样啊?
麻烦各位了!!
解决方案 »
- test() == true 和 true == test() 有什么区别?
- 单生产者 多消费者问题
- 关于系统的类提供的native方法的问题
- 关于Swing中用按钮做超链接
- 急求有检索功能的java api chm文档?
- 关于《google面试题第17题》的解答,不知道是不是google想要的答案,希望各位网友纠正错误和不足!
- 用 appletviewer 可以正常的显示applet,但是在ie里面却不能显示
- 怎样在JAVA中获取随机数?
- 安装, 出错, 问题, 着急 ,解决, 100分, 容易, 你的, 谢谢!
- 修改了程序后,web reload为什么结果不变?
- 请叫个字符串问题
- 有关comparable,谢谢!!!!
而你的父类没有无参数构造函数
在子类中添加
compute(int m,int n)
{
super(m,n);
}
就可以了
compute()
{
}也能行
compute_2(int m,int n)
{
super(m,n);
}
才对吧?而lixin199036061兄的方法虽然可以使compute_2的编译通过,不过调用compute_2时会出错,提示:cannot resole symbol
我觉得奇怪的是再加个空的构造函数,岂不是有两个构造函数了吗,可以这样的?