Untitled

mail@pastecode.io avatar
unknown
plain_text
22 days ago
921 B
3
Indexable
Never
// Player interface
interface Player {
    void play(); 
}

// Child class
class Child implements Player {
    @Override
    public void play() {
        System.out.println("A child is playing with toys.");
    }
}

// Musician class
class Musician implements Player {
    @Override
    public void play() {
        System.out.println("A musician is playing an instrument.");
    }
}

// Actor class
class Actor implements Player {
    @Override
    public void play() {
        System.out.println("An actor is playing a role on stage.");
    }
}

// Application class
public class UsePlayer {
    public static void main(String[] args) {
        // Create objects of different types
        Player child = new Child();
        Player musician = new Musician();
        Player actor = new Actor();

        // Use the play method on each object
        child.play();
        musician.play();
        actor.play();
    }
}
Leave a Comment