• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

An urgent doubt

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does the getConnection(....) method of DriverManager class return a Connection object?Connection is an interface and you cannot create object of an interface.Ditto for Statement and ResultSet..Plz explain
 
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can return a class which implements the interface and catch it as an interface.
interface InterOne{
//...methods
}
public class AnyClass implements InterOne {
public InterOne createCopy(){

return new AnyClass();
}

public AnyClass createAnotherCopy(){

return new AnyClass();
}
}
class AnyTestClass (){
public static void main(String [] args){
AnyClass Test1 = new AnyClass();

InterOne sample = Test1.createCopy();
InterOne anotherSample = Test1.createAnotherCopy();
}
}

And same stuff goes for the abstract class Change Interface declaration to an abstract class
 
Manoj Chandran
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx for reply.But then the object of which class does getConnection method return?
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic