JDBC- Implementation of interfaces

后端 未结 5 1094
青春惊慌失措
青春惊慌失措 2020-11-29 13:53

In JDBC, to connect and execute statements in DB we mainly make use of Connection,Statement and ResultSet which are interfaces. But their corresponding objects is later use

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 14:43

    These guys are answering your question but I don't think that you are getting it from the comments.

    You need to actually implement the interface by creating your own class. So create a class that implements the interface, include the correct abstract methods, and then add whatever you want to the functionality in your new class. Then you'll instantiate that class to use the functions.

    An interface is like a programming "contract" it's there to make sure that any class used that extends the interface fulfills certain functions, however, you can't instantiate the interface itself to use its' methods, you inherit them/override them in your new class. After you override the abstract methods in your new class you can program in whatever else you want your particular interface extension class to do.

    http://www.javabeginner.com/learn-java/java-abstract-class-and-interface and http://www.javaworld.com/javaworld/javaqa/2001-04/03-qa-0420-abstract.html will let you read up on these topics.

提交回复
热议问题