repl.it
@kenanhancer/

PolymorphismDemo4

Java

No description

fork
loading
Files
  • Main.java
  • jdt.ls-java-project
  • Animal.java
  • Fish.java
  • Goldfish.java
  • OtherAnimal.java
  • Wolf.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.util.*;

class Main {
  public static void main(String[] args) {
    List<Animal> animals = new LinkedList<Animal>();

    animals.add(new Animal());
    animals.add(new Wolf());
    animals.add(new Fish());
    animals.add(new Goldfish());
    animals.add(new OtherAnimal());

    for (Animal animal : animals) {
      animal.eat();
    }
  }
}
?