Is there any difference in the polymorphism encoded below? Basically, is there a difference in binding method calls?
Polymorphism Type 1:
class A { public void method() {
Now I do things with B using A
A a = new B(); a.method();
Type of polymorphism 2:
public interface Command { public void execute(); } public class ReadCommand implements Command { public void execute() {
Now I use the factory command:
Command c = CommandFactory.getCommand("Read"); c.execute();
My question is: is there a difference in the above two polymorphisms. I know that both are examples of run-time polymorphism, but is there a difference [regarding method bindings] or any other difference in this regard?
source share