In Java, to use the super keyword, do I need to import the target class?

When we use the super keyword in the constructor, do we need to import the class referenced by super (when super does not refer to Object)?

class A extends ... {
    A() {
        super(); // do we need to import the class super refers to?
    }
}
+3
source share
2 answers

Yes, because he is in the offer extends.

Itself super()does not require import, but in order to make sense, you need a superclass. You do not need to import it, of course, if it is fromjava.lang

+10
source

You need to import the superclass if it is not in the same package or is in java.lang. If the base class is unavailable, it super()doesn't work anyway.

+1
source

Source: https://habr.com/ru/post/1785595/


All Articles