We know,interface can never instantiate in java. We can, however, refer to an object that implements an interface by the type of the interface
public interface A
{
}
public class B implements A
{
}
public static void main(String[] args)
{
A test = new B(); //upcating
//A test = new A(); // wont compile
}
But I have become confused when interface is used return type,such as
Method of DriverManager class which return Connection object
public static Connection getConnection(String url);
Connection con=DriverManager.getConnection(String url);
Same problem
Method of Connection interface which return Statement object
public Statement createStatement();
Statement stat=con.createStatement();
I cannot understand,what happened when interface is used return type. Please help me by explain.
Thanks