+ 1

In factory design how we are able to create object of an interface

15th Jul 2017, 5:18 PM
rahul garg
rahul garg - avatar
2 Respuestas
+ 2
You can't instantiate an interface. You can instantiate a class that implements an interface though. You can also refer to an object that implements that interface by the interface in a polymorphic way. MyInterface obj = new MyInterface(); is not valid. class A implements MyInterface {} A obj = new A(); is valid as is: MyInterface obj = new A(); This doesn't instantiate an interface, but uses the interface to refer to an instantiated object in a polymorphic way.
15th Jul 2017, 5:39 PM
ChaoticDawg
ChaoticDawg - avatar
0
I am not sure but interface cannot be instatiated..
15th Jul 2017, 5:40 PM
Pavel Václavík
Pavel Václavík - avatar