Jitendra Manjani
Jitendra Manjani

Reputation: 3

How can we create an object of Connection even when it's an interface?

Here we have created an object of an interface. How's that even possible?

Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","xweb","abc");

Upvotes: 0

Views: 66

Answers (1)

DBug
DBug

Reputation: 2566

No, you are creating a instance of a class that implements the interface. What that means is that you do not need to know the concrete class implementation of the object, just that it implements Connection, and as such has all the methods defined in interface Connection. If you look at con.getClass(), you will see what the actual class is.

Upvotes: 1

Related Questions