Reputation: 99
I am wondering why there isn't a dynamic binding in Java in method arguments? Example:
static class C {
public static void test(C c) {
System.out.println("C");
}
}
static class D extends C {
public static void test(D d) {
System.out.println("D");
}
}
public static void main(String[] args) {
C c = new D();
D d = new D();
test(c);
It has to be anyway determined, whether variable c contains the instance of class C or the instance of its subclass, so why can't it be done dynamically?
Upvotes: 0
Views: 280