fork download
interface Talker
{
    String talks();
}

class Pet
{
    private T pet;
    
    public Pet(T pet)
    {
        this.pet = pet;
    }
    
    public String talks()
    {
        return pet.talks();
    }
}

class Cat implements Talker
{
    public String talks()
    {
        return "Meow";
    }
}

class Dog implements Talker
{
    public String talks()
    {
        return "Woof";
    }
}

public class Main
{
    public static void main(String[] args)
    {
        Pet cat = new Pet(new Cat());
        System.out.println("Cat says " + cat.talks());
        
        Pet dog = new Pet(new Dog());
        System.out.printf("Dog says " + dog.talks());
    }
    
}
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
Cat says Meow
Dog says Woof