Garmaine Staff asked 2 years ago

How can I use a method in the interface RemoteControl in object RC while doing it this way (compiler refuses since "object" does not implement RemoteControl).

import java.util.Random;

public class DVDPlayer implements RemoteControl {

    String type;
    int currentVolume;

    @Override
    public int volumeUp() {
        currentVolume += 2;
        return currentVolume;
    }

    public static void main(String Args[]) {
        Random r = new Random();
        Object RC = null;
        if (r.nextFloat() < 0.5) {
            // make this remoteControl object reference to TV object
            RC = new TV();
        } else {
            // to DVDPlayer object
            RC = new DVDPlayer();
        }
        RC.volumeUp();

    }

}