I came across several interfaces while learning JDBC – Connection, Statement, ResultSet etc…
Does this imply that some classes somewhere, hidden from me, are implementing these interfaces, and providing their references when I need it? Is this because they need to be implemented differently depending on the Driver I’m using?
For example. It’s general best practice to code to an interface instead of an implementation (= class, in this context), for multiple reasons. One of them has been mentioned by you: related but different implementations can share a common interface. Another point is that one particular implementation can be changed behind the scenes without requiring changing the interface as well: let’s say the next implementation of the driver needs to use another class. It’s enough to implement the existing interface.
Now imagine that instead of interfaces, the code dealt with class types. Now, if the implementation changed, these interfaces would need to be changed as well. This would mean that every user (including you) of the API had to change their code as well!