What's the difference between importing and extending a class in Java
Those are two very different things.
Importing a class, is making it so you can use that class without needing to qualify the full name in the current class you are writing.
import java.util.Scanner
// now you can use the Scanner class in your code like so:
Scanner stdin = new Scanner(System.in);
// instead of having to do
java.util.Scanner stdin = new java.util.Scanner(System.in);
Extending a class is creating a new class that is a subclass of some other class. This will allow you to add or change functionality of the class you are extending.
// this is a very contrived example
public class EmptyList extends ArrayList {
@Override
public boolean add(Object o){
return false; // will not add things to a list
}
}
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