问题描述
|
以下是继承的示例
class Parent {
Parent(int a,int b) {
int c = a + b;
System.out.println(\"Sum=\" + c);
}
void display() {
System.out.println(\"Return Statement\");
}
}
class Child extends Parent {
Child(int a,int b) {
int c = a - b;
System.out.println(\"Difference=\" + c);
}
}
public class InheritanceExample {
public static void main(String args[]) {
Child c = new Child(2,1);
c.display();
}
}
当我没有非参数化的构造函数parent()时,出现以下错误
Exception in thread \"main\" java.lang.Error: Unresolved compilation problem:
Implicit super constructor Parent() is undefined. Must explicitly invoke another constructor
at Child.<init>(InheritanceExample.java:14)
at InheritanceExample.main(InheritanceExample.java:22)
您能否解释一下基类中不带参数的构造函数的目的是什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)