This is probably obvious, so bear with me.
YES, I KNOW THAT java.io.File has no default constructor.
The problem is that When I try to extend java.io.File, it says “Cannot find constructor File() in java.io.File” even though I am overriding the default constructor in java.lang.Object.
Here is my code:
AbsRelFile.java
import java.io.File;
public class AbsRelFile extends File {
File f;
private AbsRelFile(){
}
}
This gives me an error, even though I am overriding the constructor.
NOTE: This class is not finished. Don’t make a comment about why wouldn’t I need this or a comment about how this class is useless. I just started writing it before I got this Error.
Because you didn’t make an explicit call to
super(...)in your default constructor, it is implicitly attempting to call the default constructor for the super class, which, as you point out, doesn’t exist in this case (the case of super being aFile). The solution to your problem is to make a call to the super constructor in your defaultAbsRelFile()constructor. If you wan’t to provide a default constructor for your class, you’re going to need to callsuper(...)with some default values.