Question:
Connection is an interface.But how we can able to make the object of Connection interface i.e- Connection con=DriverManager.getConnection(); Can you write a program as the above statement.
Answer:
Here we are using the concept of anonymous inner class.DriverManager.getConnection() returns object of that class which implements the Connection interface,which has no name. Source: CoolInterview.com
Answered by: Deepak Kumar Sahu | Date: 5/25/2008
| Contact Deepak Kumar Sahu
Connection con=DriverManager.getConnection(-,-,-); In java we can't create the objects of interfaces. But in above code con is the object of Connection. Actually con is object of a class that implements Connection interface.The implementation class implemented by the JDBC Driver vendor.Programer no need to write that code. Source: CoolInterview.com
Answered by: venkatareddy | Date: 2/5/2010
| Contact venkatareddy
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|