Is it possible to create an object for an interface? If yes, how is it done? According to my view the following code says that we can:
Here's my understanding.
An interface
public Interface SomeInterface{
}
You can declare an Object for an interface.
SomeInterface anObject;
You cannot instantiate this object directly using this interface. However, let's say you have a class that implements this interface.
public class SomeClass implements SomeInterface {}
Then you can do this,
anObject = new someClass();
(This is conceptually of course (like pseudocode) actual code may vary depending on your classes and access modifiers etc.)
I'll update as to why exactly we are doing this/what the point is as soon as I find out.
Note: Some of this has been mentioned in above answers, just want the OP to know this whole thing too.