This is an example of what I'm trying to do, this is hard to explain so this is the simplified version using pets:
public interface Pet {
public String talk();
}
public class Dog implements Pet{
public String talk()
{
return "Woof!";
}
}
import java.util.ArrayList;
public class Person {
ArrayList<Pet> pets = new ArrayList<Pet>();
public Person()
{
pets.add(new Dog());
}
public void makePetsSpeak()
{
for(int i=0; i < pets.size(); i++)
{
System.out.println(pets.get(i).talk());
}
}
}
public class Main
{
public static void main(String [] args)
{
Person p = new Person();
p.makePetsSpeak();
}
}
When running Person.MakePetsSpeak() it returns nothing. Is what i'm doing possible or is there another way to do it?