0

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?

UFC Insider
  • 838
  • 1
  • 7
  • 19

1 Answers1

0

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".

Tobi Nary
  • 4,566
  • 4
  • 30
  • 50