This feels like a silly question, but it aggravates me as I don’t understand where the methods are declared. In my code I can do things like (obviously this is a bit pseudo code)
ResultSet rs = DB.getConnection.sendSQL(select * from [table])
I understand that the sending of the SQL returns a ‘result set’ and although a ‘ResultSet’ is only an interface the returned object implements that interface.
My question is how does the returned object implement that interface? From what I read interface can only define a method signature, not a complete function.
So where are the functions defined? Obviously not in the ResultSet interface! Am I correct in understanding that this the job of the database Driver? (I think I may have just answered my own question).
Can I write an interface with a fully functioning method? Will any implementing classes then automatically implement that method, or do I just overwrite it with a call to ‘super’ or something?
I just found this other question on SO
How does abstract method of predefined interface like Connection, Statement etc. perform some task without having body?
which is a perfect duplicate, but much bette formulated. And a great answer
Classes that implement an interface are responsible for declaring all of the methods in the interface, and where appropriate implementing the internal logic for those methods.
The interface is essentially saying “You have to provide functionality for this, but I don’t care how you do that. You just have to take inputs of these types and provide output of this type.” The class is where you implement how you get from the inputs to the outputs.