class X{
X(){
System.out.println("Inside X()");
}
X(int x){
System.out.println("Inside X(int)");
}
}
class Y extends X{
Y(String s){
System.out.println("Inside Y(String)");
}
Y(int y){
super(1000);
System.out.println("Inside Y(int)");
}
}
class Z extends Y{
Z(){
System.out.println("Inside Z()");
}
Z(int z){
super(100);
System.out.println("Inside Z(int)");
}
}
public class Program{
public static void main(String args[]){
Z z=new Z(10);
}
}
上面的代码在编译时给出以下错误:-
Program.java:23:错误:没有为 Y 找到合适的构造函数(无参数)
Z(){
^
constructor Y.Y(String) is not applicable
(actual and formal argument lists differ in length)
constructor Y.Y(int) is not applicable
(actual and formal argument lists differ in length)
1 个错误
当我们调用参数化构造函数时,默认构造函数有什么用,java编译器给出错误我无法理解为什么需要这个默认构造函数?
偶然的你
相关分类