The following pseudocode works, which is probably no surprise to anyone who's done any JDBC work:
ResultSet rs = foo.executeQuery();
boolean hasNext = rs.next();
while(hasNext) {
bar();
boolean hasNext = rs.next();
}
ResultSet (java.sql.ResultSet) is an interface, so there should be no implementation for next(), only a method declaration. So how does the code run successfully? The best answer I found online is that what comes back is an instance of a class that implements the ResultSet interface.
That answer makes sense to me (it confirms what I assumed before I actually looked it up), but it only leads to another question: how do you know what kind of class you're getting back? Couldn't it, in theory, be something that overrides the interface's method in an unexpected or undesirable way?