Java OCA OCP Practice Question 2015

Question

Which of these obtains a Connection?.

A.   Connection.getConnection(url)
B.   Driver.getConnection(url)
C.   DriverManager.getConnection(url)
D.   new Connection(url)


C.

Note

Connection is an interface.

Since interfaces do not have constructors, Option D is incorrect.

The Connection class doesn't have a static method to get a Connection either, making Option A incorrect.

The Driver class is also an interface without static methods, making Option B incorrect.

Option C is the answer because DriverManager is the class used in JDBC to get a Connection.




PreviousNext

Related