15 lines
436 B
Java

public class Program {
public static void main(String[] args) {
// because cat and dog are subclasses of animal, they can be stored in an array of animals
Animal[] animals = {
new Dog("buster"),
new Cat("mittens")
};
for (Animal a : animals) {
// when calling the make_sound function, the implementation of the actual class gets called (in this case cat or dog)
a.make_sound();
}
}
}