class Main {
private animals = [new Dog(), new Cat()];
randomWalk() {
const index = Math.round(Math.random());
const animal = this.animals[index];
// This doesn't work
animal.walk();
}
}
Then animal.walk will not work at all. The compiler completely skips it since it sees just an interface and not a concrete class.
If we had an interface for example:
And then we have a class like:
Then
animal.walk
will not work at all. The compiler completely skips it since it sees just an interface and not a concrete class.