I think that it means that via the concept of polymorphism, a variable’s type can be declared to be that of an interface. For ex: if Animal is an interface, you could code the following:
Animal simba = new Lion();
Am I correct in my understanding of this? Thanks for any help.
Every object has a type (and a value).* There are many types: primitive types (like
int), class types (likestring), enums, arrays (and perhaps I’m forgetting some).The term “interface” refers to a particular sort of class type: it is a class which has no member objects (safe constants) and only public methods, all of which are abstract.**
So: an interface is a special sort of class, which in turn is a special sort of type. So interfaces are types. In your example, both
AnimalandLionare types, and one happens to be convertible to the other.*) Loosely, the type says “what is the structure of this”, and the value says “what is the content of this”. The type of
5isint, and its value is… well, 5.**) This enables you to inherit from multiple interfaces, while it is not possible in Java to inherit from multiple general classes.