In the following code, I have two different ways to instantiate an object of class B
.
public interface A {}
public class B implements A {}
public static void main(String[] args)
{
A test1 = new B();
B test2 = new B();
}
What is the difference between the variables test1 and test2?
When should I instantiate using the Interface type (type1) and when should I not?