When, in a constructor, we use the super keyword, do we have to import the class the super refers to (when super doesn't refer to Object)?
class A extends ... {
A() {
super(); // do we need to import the class super refers to?
}
}
Yes, because it is in the extends clause.
The super() itself requires no imports, but for it to make sense you need a superclass. You don't need to import it, of course, if it is from java.lang
You do need to import the super class if it is not in the same package or it is in java.lang. If the base class is not available, super() doesn't work anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With