Implicit super constructor Array() is undefined for default constructor. Must define an explicit constructor

Because your parent has created a parameterized constructor of the parent class and there is no no-argument constructor, then the compiler will not call the default constructor for you,

So subclass inherits the parent class when needed in their constructor explicitly call the parent class constructor, so as to ensure that the subclass initialized before the parent class will be instantiated.

The parent class constructor Ruoguo no-argument, the subclass is not required to do, the compiler will help you automatically call the default no-argument constructor. (Bold behalf constructor)

package ssm;

public class Array {
private int arr[];
private int index;

public Array(int len) {
if (len > 0) {
this.arr = new int[len];
} else {
this.arr = new int[1];
}
}

public boolean add(int i) {
if (this.index < this.arr.length) {
this.arr[index] = i;
index++;
return true;
} else {
return false;
}
}

public int[] getArray() {
return this.arr;

}
}

 

package ssm;

public class ReverseArray extends Array {

public ReverseArray (int len) {
super (len);
}

}

 

Guess you like

Origin www.cnblogs.com/wangffeng293/p/11769442.html
Recommended