public class Dog extends Animal{
public void noise(){
System.out.println("Ruff");
}
}
public class Fish extends Animal{
public void noise(){
System.out.println("Gree");
}
}
public class Animal {
public void noise(){
System.out.println("Animal dint amke noise");
}
}
public class Main {
public static void main(String[] args){
Animal[] thelist = new Animal[2];
Dog d = new Dog();
Fish f = new Fish();
thelist[0] = d;
thelist[1] = f;
for(Animal x: thelist){
x.noise();
}
}
}
the result is ;
Ruff
Gree