devxlogo

ResultSet Interface

ResultSet Interface

Question:
If ResultSet is an interface, then why can we call methods like

next(), isLast()

etc. without defining the method body anywhere in the program? As I understand it, in an interface, methods are only declared but not defined.

Answer:
Even though an interface does not implement any of its methods, a class that implements an interface will implement the interface’smethods. When you obtain a reference to a ResultSet through a JDBC call, you are getting an instance of a class that implements the ResultSet interface. This class provides concrete implementations of all of the ResultSet methods.

Interfaces are used to divorce implementation from, well, interface. This allows the creation of generic algorithms and the abstraction ofobject creation. For example, JDBC drivers for different databases will return different ResultSet implementations, but you don’t have tochange your code to make it work with the different drivers.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist