Well this type of questions have been answered already but this confused me. I have spent lot of time going through lots of answer so please go through my question before making it duplicate.
case 1 -
static polymorphism - function overloading dynamic polymorphism - function overriding
links - https://stackoverflow.com/a/12894211/3181738 https://stackoverflow.com/a/20783390/3181738 and many others.
My confusion is that in all the examples dynamic polymorphism is shown using upcasting. What if I don't upcast.
class A{
public void show(){
System.out.print("A");
}
}
class B extends A{
public void show(){
System.out.print("B");
}
public static void main(String[] s){
A a = new B();
a.show(); // upcasting. It is dynamic polymorphism.
B b = new B();
b.show(); // Now java compiler can decide so is it still dynamic polymorphism?
}
}
case 2 -
static polymorphism is achieved via overloading if method is private , static or final.
So what about overloading of public and default methods?