在下面的代码中,我有两种不同的方法来实例化类的对象B.
public interface A {}
public class B implements A {}
public static void main(String[] args)
{
A test1 = new B();
B test2 = new B();
}
Run Code Online (Sandbox Code Playgroud)
变量test1和test2有什么区别?
我何时应该使用Interface类型(type1)进行实例化,何时不应该?