Hi,
I understood the confusion that you have.
Well, those type of statements are allowed in
Java. The first line
is a declaration, whereas
is initialization.
An interface is nothing but an 100% abstract class. During the declaration part, you are declaring an object that may contain any class that implements the interface. We used to tell that the classes or interface that have inheritance as their relationship, is having a "IS-A" relationship. For example, if I have a class named Bird, and if i inherit this class in "Pigeon" class, then we tell that "Pigeon is-a bird".
This will be useful in accessing a common method, that are present in all the subclasses. Again for example, if i have one more class in the above example, say, "Parrot", and if i want to call the fly() [assume we have it] method in both the classes, it is efficient to use a Bird class object [even if it is an interface], and store an instance of Parrot or Pigeon. At runtime, the JVM decides the object to invoke the method.
This is runtime
polymorphism.