Question (What my code is trying to achieve in terms of interfaces? (Compile - time / run - time) polymorphism ?
Consider below code as an example
interface RemoteControl {
void turnOn();
void turnOn(int channel);
}
class TV implements RemoteControl {
public void turnOn() {
System.out.println("TV is turned on");
}
public void turnOn(int channel) {
System.out.println("TV is turned on. Channel: " + channel);
}
}
public class UserCode {
public static void main(String[] args) {
RemoteControl tvRemote = new TV();
tvRemote.turnOn();
tvRemote.turnOn(5);
}
}
Now in the above code can you tell me what type of polymorphism its trying to achieve.?
So below part is decided at compile-time or run-time ( as there are not inherited classed but in terms of interface ?
RemoteControl tvRemote = new TV();
tvRemote.turnOn();
tvRemote.turnOn(5);