For example Noise is an interface and Animal is a class that implements Noise. Why can I write under main:
Noise n = new Animal();
And what is the meaning of it?
For example Noise is an interface and Animal is a class that implements Noise. Why can I write under main:
Noise n = new Animal();
And what is the meaning of it?
Because interfaces can be used as types. You are then restricted to the methods declared in the interface, independent of the implementing class.
It means "I want a new animal to be stored in n
, but I will ever only need it's Noise
features, so let me only use those methods on n
".