Compile Time and Runtime Polymorphism is directly related to when the calls are resolved.
In compile Time Polymorphism, the calls are resolved during compile time. Method over loading is an example of Compile time Polymorphism. Overloading is irrespective of whether it is at instance level or class level
Example :
public class Sample {
static void doSomething(InputStream is) {
System.out.println("is");
}
static void doSomething(OutputStream os) {
System.out.println("os");
}
public static void main(String args[]) {
System.out.println(doSomething(null));
}
}
Next, Runtime Polymorphism : Here the calls / method signatures are checked for existence during compile time but the actual calls are resolved during runtime.
Example :
class ParentOfSample {
void testingOverriding(String s) {
System.out.println("Parent..");
}
}
public class Sample extends ParentOfSample {
static void doSomething(InputStream is) {
System.out.println("is");
}
static void doSomething(OutputStream os) {
System.out.println("os");
}
void testingOverriding(String s) {
System.out.println("Sample..");
}
public static void main(String args[]) {
ParentOfSample s = new Sample();
s.testingOverriding(null);
}
}
O/P :
Sample. Note that during Overriding the method signatures are the same.
So, the bottom line is : The second case is right. Java supports both static and dynamic polymorphism.