Home > Archive > Java Help > February 2006 > Re: ResultSet Object ? I Thought you can't instantiate an Interface. - What's going o
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: ResultSet Object ? I Thought you can't instantiate an Interface. - What's going o
|
|
| grasp06110 2006-02-24, 7:01 pm |
| Hi Hal,
You cannot create an instance of an interface directly. For example
the following will not work.
ResultSet rs = new ResultSet()
An instance of an interface can be created by creating an instance of a
class that implements that interface.
If you do something like the following you will be able to see the
actual class that is being returned by statement.executeQuery(strQuery)
ResultSet rs = statement.executeQuery(strQuery);
System.out.println(rs.getClass().getName());
The following should also work:
interface MyInterface {
public void doSomething();
}
class MyClass implements myInterface {
public void doSomething() {
System.out.println("success");
}
class client {
public static void main(String[] args) {
MyInterface mi = new MyClass();
mi.doSomething();
}
}
Hope this helps,
Grasp
| |
| Hal Rosser 2006-02-24, 7:01 pm |
|
"grasp06110" <grasp06110@yahoo.com> wrote in message
news:1140798458.507868.178740@j33g2000cwa.googlegroups.com...
> Hi Hal,
>
> You cannot create an instance of an interface directly. For example
> the following will not work.
>
> ResultSet rs = new ResultSet()
>
> An instance of an interface can be created by creating an instance of a
> class that implements that interface.
>
> If you do something like the following you will be able to see the
> actual class that is being returned by statement.executeQuery(strQuery)
>
> ResultSet rs = statement.executeQuery(strQuery);
> System.out.println(rs.getClass().getName());
>
> The following should also work:
>
OK - thanks. I was referring to the examples that are shown in Sun's JDBC
tutorial, which used the executeQuery method of the Statement object to
instantiate the ResultSet.
So - it was actually a class that implements the ResultSet Interface, right?
|
|
|
|
|