Polymorphism is the ability of an object to take on many forms. There are two types of polymorphism in java- Runtime polymorhism ( Dynamic polymorphism) and Compile time polymorphism (static polymorphism).
Method overriding is a perfect example of runtime polymorphism. Since in method overriding both the classes(base class and child class) have same method, compile doesnt figure out which method to call at compile-time. In this case JVM(java virtual machine) decides which method to call at runtime thats why it is known as runtime or dynamic polymorphism.
Compile time polymorphism is nothing but the method overloading in java.In simple terms we can say that a class can have more than one methods with same name but with different number of arguments or different types of arguments or both.
Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!