instantiate a interface as object

We have interfaces   java.sql.Connection
                &    java.sql.CallableStatement


how to explain

      Connection        _con=Drivermanager.getConnection();
      CallableStatement stmt = _con.prepareCall("...");
      stmt.setInt(...);
      stmt.registerOutParameter(1, Types.INTEGER);
      ResultSet rs=stmt.executeQuery();


stmt is an Object or not,
Does Interface can be instantiated ???

Funny
PhoebeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

imladrisCommented:
You are correct in saying that an interface cannot be instantiated. This means that you cannot create that would only be an interface e.g.:

CallableStatement stmt=new CallableStatement();


However, that is not what is happening in the code you provide. An object of type connection is created. This object provides a method called prepareCall that returns an object of TYPE CallableStatement. In this case prepareCall creates an object of some sort, that implements the CallableStatement interface. Such an object CAN be referenced by a "pointer" of type CallableStatement.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
imladrisCommented:
Corrections:

This means that you cannot create that
should be
This means that you cannot create an object that

At the end add:
Now that the object has been created, it can be treated as a CallableStatement object.
0
mbormannCommented:
in simpler terms to what imladris explained nicely ,
the interface has say

interface Guess
{
public void XXXmethod();
}

someMethod(Guess g)

now when u say that someMethod expects a param of type Guess ,so if ANY class that implements Guess like so

class AnyClass implements Guess
{}
can be instantiated and passed to someMethod

what happens is that the place where u pass the Guess expects the pointer as imladris said with 1 method having the correct return type and signature as that declared in interface Guess namely
public void XXXmethod()

hope this clears ur doubt
0
imladrisCommented:
Is there anything else on this topic you would like clarified before you grade the answer?
0
mbormannCommented:
yesterday the auto-grader graded all 'C' to my locked questions and my points jumped by 4000 or so.
it's better to do the grading by urself and be fair to people who help us out when it's our time to ask questions.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.