【发布时间】:2018-05-30 23:03:04
【问题描述】:
我在我的程序中使用继承和超级函数,但是当我扩展我的类时,它显示错误消息“'cc'中没有默认构造函数。”。此错误消息是在扩展第一个子类并尝试创建第二个子类之后出现的。这是代码
class aa{
int i=-1;
int show(){
return i;
}
}
class bb extends aa{
int i;
bb(int g,int j){
super.i=g;
i=j;
}
}
class cc extends bb {
int j,k;
cc(int i, int j,int k) {
super(i,j);
super.i=i;
this.j=j;
this.k=k;
}
}
class dd extends cc{ // here the error showing
int h; //" There is no default constructor in 'cc' "
void hello(){
System.out.println("hello");
}
}
class SuperUseExample3 {
public static void main(String[] args) {
aa x = new aa();
System.out.println("value of a = "+x.i);
bb y = new bb(8,2);
System.out.println("value of a in class cc = "+y.show());
System.out.println("value of b in class bb = "+y.i);
cc z =new cc(12,13,14);
System.out.println("value of a in class cc = "+z.show());
System.out.println("value of b in class cc = "+z.j);
System.out.println("value of c in class cc = "+z.k);
}
}
【问题讨论】:
标签: java inheritance super